PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
QbertsBrother
Forum Commoner
Posts: 58 Joined: Thu Oct 11, 2007 10:12 am
Post
by QbertsBrother » Wed Dec 12, 2007 12:02 pm
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
nathanr
Forum Contributor
Posts: 200 Joined: Wed Jun 07, 2006 5:46 pm
Post
by nathanr » Wed Dec 12, 2007 12:24 pm
sounds like your doing a date on the number -1 check the value of mydatefield first..
QbertsBrother
Forum Commoner
Posts: 58 Joined: Thu Oct 11, 2007 10:12 am
Post
by QbertsBrother » Wed Dec 12, 2007 12:33 pm
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.
nathanr
Forum Contributor
Posts: 200 Joined: Wed Jun 07, 2006 5:46 pm
Post
by nathanr » Wed Dec 12, 2007 12:34 pm
speedy33417
Forum Contributor
Posts: 128 Joined: Sun Jul 23, 2006 1:14 pm
Post
by speedy33417 » Wed Dec 12, 2007 12:44 pm
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)));
QbertsBrother
Forum Commoner
Posts: 58 Joined: Thu Oct 11, 2007 10:12 am
Post
by QbertsBrother » Wed Dec 12, 2007 1:02 pm
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?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Dec 12, 2007 1:16 pm
I would suggest using the MySQL DATE_FORMAT() function instead of messing around with dates in PHP.
(#10850)
QbertsBrother
Forum Commoner
Posts: 58 Joined: Thu Oct 11, 2007 10:12 am
Post
by QbertsBrother » Wed Dec 12, 2007 2:30 pm
thank you very much for the help everyone.
the date_format worked great.
thanks