tags:

views:

87

answers:

3

In a recent question, someone asked if they could make a time just using the hour, minute, and AM/PM parts of a standard time format. This led to my question, what is needed to create a time using strtotime?

  • Do you need to have a date? If one is not provided, what date does it choose?
  • Do you need to have a time? What is the default?
  • Do you need to have a year? Default?
  • Month? Default?
  • Day? Default?

I guess this is more of, what are the defaults for strtotime, but I'm curious to know.

+3  A: 
  1. No; today.
  2. No; noon.
  3. No; this year.
  4. No; the current month.
  5. No; the current day.

I don't know what happens if the current day is unavailable in a specified month (e.g. it's the 31st and you do strtotime('February'). Someone who has a server instance available where they can safely manipulate the system time could research that.

chaos
iirc it takes the first day of the next month, but i didn't test it.
Scharrels
A: 

See http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html#SEC114 and http://us2.php.net/manual/en/function.strtotime.php

The default time when no time is supplied is "00:00:00" (midnight).

GZipp
A: 

Do you need to have a date? -> No. You can use 'now' as a string which will set to current date/time.

Do you need to have a time? -> No. 00:00:00 +0100 is the default.

Do you need to have a year? -> No. It uses the date in the current year with 00:00:00 time.

Do you need to have a month? Yes. If you put just the year, it returns the current date/time.

Do you need to have a day? No. It uses the first day of the month/year provided (00:00:00 time).

iano