Here is what I have:
$dateFormat = 'M d, Y';
$dateString = 'January 23, 2010';
What I need is a timestamp of $dateString
so I can do this:
$newFormattedDate = date('Y-m-d', $timestamp);
I tried to use strtotime
function but it tries to find out the format itself and doesn't work always. In my situation I know both the date string and date format.
How can I set $timestamp
to an appropriate value for use with the date
function?
EDIT: I need this to work in both Linux and Windows environments.
EDIT: The solution must support PHP version 4 or higher
EDIT: MySQL has a function called STR_TO_DATE
which takes a date string and a date format and returns Y-m-d
formatted date string. Any equivalent function for php works for me also.