aniltc Posted November 16, 2006 Share Posted November 16, 2006 hi all I am new to php. I have a problem in my site.I have a news and Events section in my home page,in which i want to display the latest news and events based on current server date.I am storing entire date in the database.[u]database structure[/u]Input to Mysql databaseDATE(dd-mm-yyyy) News and EVENTS8-10-2005 XXXXXXXXXX8-10-2006 XXXXXXXXXX1-11-2006 XXXXXXXXXX14-11-2006 XXXXXXXXXX16-11-2006 XXXXXXXXXX18-11-2006 XXXXXXXXXX30-12-2006 XXXXXXXXXX#########################################################I need the o/p in the following format(consider 16-11-2006 is the current Server date)DATE(dd-mm-yyyy) News and EVENTS16-11-2006 XXXXXXXXXX18-11-2006 XXXXXXXXXX30-12-2006 XXXXXXXXXX14-11-2006 XXXXXXXXXX 01-11-2006 XXXXXXXXXX 8-10-2006 XXXXXXXXXX8-10-2005 XXXXXXXXXX please help me the logic or providing the code >:( Link to comment https://forums.phpfreaks.com/topic/27446-date-display-in-php/ Share on other sites More sharing options...
Orio Posted November 16, 2006 Share Posted November 16, 2006 I cant see a pattern in the date order... What are you exactly trying to achieve? (explain in english)Orio. Link to comment https://forums.phpfreaks.com/topic/27446-date-display-in-php/#findComment-125531 Share on other sites More sharing options...
printf Posted November 16, 2006 Share Posted November 16, 2006 I would really think about using one of the databases default date types, as it would make doing this so much easier. Why because your [b]dd[/b] could have (1) or (2) digits and your [b]mm[/b] could have (1) or (2) digits, which would require you to use IF() conditions just to format the date for sorting! If you want a query to fix your date column then show me exactly the real data so I can see if your [b]mm[/b] has always 2 digits or (1) or (2)... Link to comment https://forums.phpfreaks.com/topic/27446-date-display-in-php/#findComment-125534 Share on other sites More sharing options...
aniltc Posted November 17, 2006 Author Share Posted November 17, 2006 Hi I am not geeting what u r saying.Can u plz explain little bit.my field type is varcharATC Link to comment https://forums.phpfreaks.com/topic/27446-date-display-in-php/#findComment-126019 Share on other sites More sharing options...
jawapro Posted November 17, 2006 Share Posted November 17, 2006 If you use something like the date field in Mysql instead of a Varchar it will make things easier. You can do things like say "SELECT * FROM whatever ORDER BY date DESC" or similar (writting from the top of my head - but its close). That would like all the things in order (newest first).If you are using a varchar you cant easily do a ORDER BY sort of operation. Link to comment https://forums.phpfreaks.com/topic/27446-date-display-in-php/#findComment-126020 Share on other sites More sharing options...
The Little Guy Posted November 17, 2006 Share Posted November 17, 2006 These two dates are formatted differently, If you format the dates differently like this, it won't work.01-11-20068-10-2006 Link to comment https://forums.phpfreaks.com/topic/27446-date-display-in-php/#findComment-126023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.