tags:

views:

56

answers:

3

hi ,

I want to convert this date ( 02-12-2010) mm-dd-yyyy to time format

ie

to 02-12-2010 0 hours 0 minutes and 0 seconds

i have user time and date functions but when i refresh the page its value is changing as per the time.

i need that to be fixed

also i want to convert this date (01-24-2009) to time format.

please help me

Thanks

+1  A: 

Use the strtotime function to convert an existing date/time string into a timestamp for the date function.

$new_date = date('m-d-Y h:i:s', strtotime('02-12-2010'));

The reason that your date keeps updating with the current time is that the date() function uses the current system's timestamp by default when no second parameter is provided.

Cryo
A: 

Use the date_parse_from_format () API function to transform your given format to an array. E.g.

$date = "02-12-2010";
$dateArr = date_parse_from_format("d-m-Y", $date);

Output it with something like:

$output = $dateArr['day'] . '-' . $dateArr['month'] '-' . $dateArr['year'];
TheGrandWazoo
A: 

You can use the strtotime function eg:

$mydate = date('m-d-Y h:i:s', strtotime('02-12-2010'));
Sarfraz