-2

Given a date string formatted Y-m-d (2014-4-11 for example), how can I get a UNIX timestamp of 12am the beginning of that day? Would it involve date_parse_from_format()?

Thanks

1 Answer 1

1

You can simply use strtotime()

$date = "2014-04-11";
$timestamp = strtotime($date);

which inturm gives you -

$d = date('Y-m-d H:i:s', $timestamp);  // 2014-04-11 00:00:00

Try online conversion to test - http://www.onlineconversion.com/unix_time.htm

2
  • Sorry, I should have specified, I'm looking to output a UNIX timestamp (seconds since Jan 1st, 1970)
    – conbask
    Apr 11, 2014 at 18:59
  • 1
    Yes. Then can simply echo $timestamp above. It'll give you UNIX Timestamp of the date. Apr 11, 2014 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.