Jump to content

[SOLVED] help with a string


garry

Recommended Posts

So I have a string containing a date and time in the following format

 

22 Oct 2008 12:45:00 PM

 

Basically, I need some sort of regex to split up the date and the time into two different variables.. I've tried playing around with some but I haven't quite got it, i'm not so great at expressions. Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/140802-solved-help-with-a-string/
Share on other sites

You need to use the strtotime function on the string before passing it to the date function:

<?php
$str = '22 Oct 2008 12:45:00 PM';
echo date('Y-m-d',strtotime($str)) . "<br>\n";
echo date('g:i',strtotime($str)) . "<br>\n";
?>

 

Ken

 

 

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.