Page 1 of 1
using date()
Posted: Wed Dec 12, 2007 12:02 pm
by QbertsBrother
hello all
i have a date stored in a mysql database and when i do a query and select the date and use this
it shows all the dates as 12.31.69
i dont know why it is doing this. anyone have any suggestions on how to get the formating correct?
thanks
Posted: Wed Dec 12, 2007 12:24 pm
by nathanr
sounds like your doing a date on the number -1 check the value of mydatefield first..
Posted: Wed Dec 12, 2007 12:33 pm
by QbertsBrother
mydatefield is a Date datatype in a mysql database.
the value of mydatefield looks like this but with different dates.
2007-12-01
2007-12-02
2007-12-03
2007-12-12
what ever the date is that the record was entered.
Posted: Wed Dec 12, 2007 12:34 pm
by nathanr
Posted: Wed Dec 12, 2007 12:37 pm
by QbertsBrother
d.m.y produces 31.12.69
Posted: Wed Dec 12, 2007 12:44 pm
by speedy33417
I've had so much trouble with date() back a few months ago, so I was just happy to get it working. It's probably not the prettiest code, but it works for me.
Code: Select all
$updatedDate = date('Y-m-d', strtotime("", strtotime($date)));
Posted: Wed Dec 12, 2007 1:02 pm
by QbertsBrother
Code: Select all
$updatedDate = date('Y-m-d', strtotime("", strtotime($date)));
still produces 12.31.69
the funny if i just use this
it produces todays date correctly.
do i need to change the datatype of the data to something else?
Posted: Wed Dec 12, 2007 1:16 pm
by Christopher
I would suggest using the MySQL DATE_FORMAT() function instead of messing around with dates in PHP.
Posted: Wed Dec 12, 2007 2:30 pm
by QbertsBrother
thank you very much for the help everyone.
the date_format worked great.
thanks