Changing date format

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

Post Reply
MrToast
Forum Newbie
Posts: 3
Joined: Mon Jun 13, 2005 9:17 am
Location: Land of the Golden Gophers

Changing date format

Post by MrToast »

Hi everyone,

I've got a date string I'm pulling off of a website that's in the form:

Code: Select all

Jun. 21st, 2005 @ 11:53 am
What would be the best way to go about converting this to a PHP-usable date? I've checked out the "strtotime()" function, but that returns -1 (ie it couldn't convert the string).

Any ideas?

Thanks!

MrToast
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

try removing the @ sign

Code: Select all

$date = str_replace("@", "", "Jun. 21st, 2005 @ 11:53 am");
$unix_date = strtotime( $date );
MrToast
Forum Newbie
Posts: 3
Joined: Mon Jun 13, 2005 9:17 am
Location: Land of the Golden Gophers

Post by MrToast »

Well, this is a step in the right direction!

After taking out the "@" and trying strtotime() again, I now end up with

Code: Select all

Wed, 31 Dec 1969 15:59:59 -0800
instead of "-1".

So... progress... kinda.... :? ;)

MrToast
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

just tested it, it worked for me
show the rest of the code

for a mysql date field it should be something like this

Code: Select all

$date = date("Y-m-d H:i:s", strtotime( str_replace("@", "", "Jun. 21st, 2005 @ 11:53 am")));
MrToast
Forum Newbie
Posts: 3
Joined: Mon Jun 13, 2005 9:17 am
Location: Land of the Golden Gophers

Post by MrToast »

Thanks, that worked! :D

MrToast
Post Reply