Questions tagged [strtotime]

PHP function for parsing about any English textual datetime description into a Unix timestamp

Samples

strtotime('first day of this month');
strtotime('last day of this month');
strtotime('-1 month'); # current date -1 month
1308 questions
13
votes
5 answers

strtotime('today') returning incorrect time?

I am trying to create a select list starting from the current date of the user. I want it so that it is set to midnight in unix timestamp format. This is all I'm doing: $today = strtotime('today'); echo $today; This is my result: 1333144800 which…
Johnathan Au
  • 5,244
  • 18
  • 70
  • 128
13
votes
3 answers

force php strtotime to use UTC

I've seen a few questions about this but not a clear answer... strtotime() will use the default timezone set for PHP when converting the string to a unix timestamp. However, I want to convert a string to unix timestamp in UTC. Since there is no…
Brian
  • 7,204
  • 12
  • 51
  • 84
13
votes
1 answer

Is there any difference in strtotime +day or +days?

Was googling this, but couldn't find the answer. Was wondering, if there is a difference in these two scripts? +3 day: echo date( 'd.m.Y H:i:s', strtotime( '+3 day' ) ); +3 days: echo date( 'd.m.Y H:i:s', strtotime( '+3 days' ) ); The output is…
Peon
  • 7,902
  • 7
  • 59
  • 100
12
votes
5 answers

PHP strtotime returns a 1970 date when date column is null

I want to display $row->depositdate in dd-mm-yyyy format. If the date column in database is null the date displayed is : 01-01-1970 echo "".date('d-m-Y', strtotime($row->depositdate)).""; If the date is null in database it…
Sandy505
  • 888
  • 3
  • 15
  • 26
12
votes
2 answers

PHP strtotime to return as UTC timestamp?

Its a bit of a sever difference problem. On my local dev. server Im using: The above code gives me the correct timestamp for my timezone. HOWEVER, the same code returns false on the live server. The live…
CodeChap
  • 4,132
  • 6
  • 30
  • 40
12
votes
7 answers

strtotime() considered harmful?

It seems like a lot of people struggle with date/time issues in PHP, and inevitably, many of the accepted answers tend to be "Use strtotime in this way." Is this really the best way to direct people dealing with date problems? I'm beginning to feel…
Yahel
  • 37,023
  • 22
  • 103
  • 153
12
votes
4 answers

PHP strtotime returning always midnight

I'm having a weird problem. When I do strtotime it's not considering the hours part of the original date, and it's always returning midnight. I tried to research but I couldn't find anything specific. Is there something I'm missing? $original_date =…
Kitara
  • 401
  • 1
  • 3
  • 15
11
votes
6 answers

Getting first weekday in a month with strtotime

I'm trying to figure out the first wednesday of a given month using strtotime, but the "first wednesday" argument fails whenever the first wednesday happens to fall on the 1st. For a more general illustration of this problem, see the following code…
Yarin
  • 173,523
  • 149
  • 402
  • 512
11
votes
1 answer

PHP strtotime incrementing by weekdays

Today is Friday, April 17, 2015. In my app, it automatically generated a "due date" for each assignment. It's set to "5 business days". To accomplish this, We use: date('m/d/Y', strtotime("+5 weekdays")); However, today, this output…
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
11
votes
6 answers

How to make strtotime parse dates in Australian (i.e. UK) format: dd/mm/yyyy?

I can't beleive I've never come across this one before. Basically, I'm parsing the text in human-created text documents and one of the fields I need to parse is a date and time. Because I'm in Australia, dates are formatted like dd/mm/yyyy but…
Iain Fraser
  • 6,578
  • 8
  • 43
  • 68
10
votes
1 answer

Is there an R equivalent of strtotime

PHP has this wonderful function, strtotime, that takes any string containing just about any date format and returns a time (secs-since-1970). It is more future-proof than strptime, for instance, because if the date format changes my script does not…
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
10
votes
5 answers

PHP: strtotime is returning false for a future date?

here are some debug expressions i put into eclipse, if you don't believe me: "strtotime("2110-07-16 10:07:47")" = (boolean) false "strtotime("2110-07-16")" = (boolean) false i'm using it in my function which returns a random date between the…
Garrett
  • 11,451
  • 19
  • 85
  • 126
10
votes
1 answer

php date less than another date

given this kind of date object date("m/d/Y", strtotime($numerical." ".$day." of ".date("F"))) where it may give a mm/dd/yyyy day that is the "first Monday of August", for instance how can I decide if this date is greater than, less than, or equal…
CQM
  • 42,592
  • 75
  • 224
  • 366
9
votes
2 answers

How to find the first day of the week a given date belongs to?

Possible Duplicate: Get first day of week in PHP? Given a timestamp I need to find the first day the week the timestamp belongs to. e.g. $format = "first day of week"; //convert to time $time = strtotime("2011-07-01 00:00:00"); //format the…
woot586
  • 3,906
  • 10
  • 32
  • 40
9
votes
4 answers

Getting all dates for Mondays and Tuesdays for the next year

I need to output a list of dates (only Mondays and Tuesdays) for the next 12 months from current date like so: Jan 2010 Tue 12 Jan 2010 Mon 18 Jan 2010 Tue 19 Jan 2010 Mon 25 Jan 2010 Feb 2010 Tue 02 Feb 2010 Mon 08 Feb 2010 Tue 09 Feb 2010 Mon 15…
interrogativus
  • 123
  • 1
  • 7