0

Bootstrap time picker gives me Date in this format:

Mon Mar 16 2015 00:00:00 GMT-0500 (Central Daylight Time)

I would like to use it as a Date object in PHP.

I am attempting to use it like:

date("Y-m-d H:i:s" , strtotime("Mon Mar 16 2015 00:00:00 GMT-0500 (Central Daylight Time)"));

But that results in:

1969-12-31 18:00:00

Which I understand to be pretty close to EPOCH.

I'm thinking I'm either using the wrong function, or I formatted date() wrong.

I am using the TimePicker from here.

1 Answer 1

1

strtotime only works on certain formats of which can be found here http://php.net/manual/en/datetime.formats.php

Mar 16 2015 00:00:00 GMT-0500

The above portion should return the right time value for you. Either change the way that the picker is outputting the date, without knowing which picker I will assume its this one http://bootstrap-datepicker.readthedocs.org/en/latest/options.html#format or do some string manipulation on the current date format from the picker (the first option would be simpler and easier to read).

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm... So I should simply do $time = strstr('Mon Mar 16 2015 00:00:00 GMT-0500 (Central Daylight Time)', ' (');?
I would change the format outputted by the bootstrap date picker to match one of the date formats listed in the php manual. Once that happens you should just be able to pass the output from the datepicker directly to strtotime

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.