Page 1 of 1
Change date format
Posted: Wed Jun 01, 2005 11:41 pm
by S_henry
Currently in my table (in database), i store date record in 'dd.mm.yyyy' format. The problem is i don't know how to display that date in 'MMM dd, YYYY' format. i've tried all the way but still can't find the right way. Anybody can help me pls?
Posted: Thu Jun 02, 2005 12:11 am
by Burrito
Posted: Thu Jun 02, 2005 1:23 am
by S_henry
If i not mistake, that code will display the current date, right? But my prob is to convert the date record from database (in 'dd.mm.yyyy' format) to 'MMM dd, YYYY' format. For example, record in database is '20.05.2005'. I want to display that record as 'May 20, 2005'. Anybody can help?
Posted: Thu Jun 02, 2005 3:10 am
by timvw
1-) Use a correct datatype for your column => date
2-) Lookup the date & time functions in your rdbms manual.
Mysql has for example DATE_FORMAT.
Posted: Thu Jun 02, 2005 8:07 am
by Chris Corbyn
timvw wrote:1-) Use a correct datatype for your column => date
2-) Lookup the date & time functions in your rdbms manual.
Mysql has for example DATE_FORMAT.
or failing that (although i strongly advise you do as timvw says)....
[Note... we get a lot of questions of this nature]
Code: Select all
$date = '02.06.2005';
$bits = explode('.', $date);
$date_stamp = strtotime($bits[1].'/'.$bits[0].'/'.$bits[2]); //Use a U.S. format for strtotime() [mm/dd/YYYY]
echo date("d M, Y", $date_stamp);
Posted: Thu Jun 02, 2005 9:27 pm
by S_henry
OK. Now the prob is solved already. Currently i'm using d11wtq's way. But just want to know, in php, can we convert the string to date? Just like we convert int to string..
Posted: Thu Jun 02, 2005 9:28 pm
by John Cartwright
Posted: Thu Jun 02, 2005 10:24 pm
by S_henry
OK. Thanx guys..
