date time to date (Y/m/d)

483 views Asked by At

I have this as my date if I use $patient['DATE_UNIT_ADM'] just as.

28/07/2012 00:00:00

but when I do this to get it to a Y/m/d format it goes back to

1970/01/01

$timestamp = strtotime($patient['DATE_UNIT_ADM']);
$AdmissionDate = date('Y/m/d', $patient['DATE_UNIT_ADM']);

Why is this. Whats happening in strtotime?

UPDATE.

there is still something funny here.

$timestamp = strtotime($patient['DATE_UNIT_ADM']);

still give no value, but doing

echo $patient['DATE_UNIT_ADM']

gives me the correct date.

any idea

var_dump returns boolean false and var_dump($patient['DATE_UNIT_ADM']) returns string '28/07/2012 00:00:00' (length=19)

SOLUTION

strtotime(str_replace("/", ".", $patient['DATE_UNIT_ADM']));

2

There are 2 answers

5
Richard On BEST ANSWER

You forgot the timestamp / are using the wrong variable (the original date time), if the code you posted is correct:

$AdmissionDate = date('Y/m/d', $timestamp);
1
Tuan Anh Hoang-Vu On

Because you are using wrong variable:

$timestamp = strtotime($patient['DATE_UNIT_ADM']);
$AdmissionDate = date('Y/m/d', $timestamp);