Jump to content

date display in php


aniltc

Recommended Posts

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 database

DATE(dd-mm-yyyy) News and EVENTS
8-10-2005                 XXXXXXXXXX
8-10-2006                 XXXXXXXXXX
1-11-2006                 XXXXXXXXXX
14-11-2006                 XXXXXXXXXX
16-11-2006                 XXXXXXXXXX
18-11-2006                 XXXXXXXXXX
30-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 EVENTS
16-11-2006               XXXXXXXXXX
18-11-2006               XXXXXXXXXX
30-12-2006               XXXXXXXXXX
14-11-2006               XXXXXXXXXX
01-11-2006                    XXXXXXXXXX
8-10-2006                 XXXXXXXXXX
8-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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.