I have dates stored in the MS SQL DB as such:
Jul 1 2008 12:00AM
But I want to display them in the following format on the PHP page:
2008-7-1
Here is my code:
//Splitting date stored in MS SQL (Ex: Jul 1 2008 12:00AM)
$expiry_date = "Jul 1 2008 12:00AM"; $expiry_y = substr($expiry_date,-12,4); // Returns 2008
$expiry_m = substr($expiry_date,0,3); // Returns Jul
$expiry_d = substr($expiry_date,4,2); // Returns 1x (where x is a whitespace)
$expiry_d = preg_replace("/\s+/", "", $expiry_d); // Clears whitespace
I'm able to get it to display...
2008-Jul-1
Now to convert the "Jul" to "7" I can just use a IF or Switch/Case condition. But is there a simple way to achieve my result without having to crop and then replace the strings with numbers?
I tried looking at the date function in PHP but was instantly lost. Please help.