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
9
votes
1 answer

Counting number of events per week in PHP

I have a table which contains members signups and I would like to be able to start doing some charting and analysis on the data and look for signup trends etc so I would like to be able to plot a line graph which shows me how many people signed up…
bhttoan
  • 2,641
  • 5
  • 42
  • 71
8
votes
2 answers

php strtotime reverse

Is there some function timetostr in php that will output today/tomorrow/next sunday/etc. from a given timestamp? So that timetostr(strtotime(x))=x
prongs
  • 9,422
  • 21
  • 67
  • 105
8
votes
1 answer

Best way to change Twitter-API datetime's to a timestamp

The Twitter API sends created_at datetimes like this: "created_at": "Mon Jul 25 05:51:34 +0000 2011", What's the best way to convert them in a timestamp and my local timezone (Europe/Zurich)? With strtotime(), I get results like 2013-11-08…
Ueli
  • 2,301
  • 5
  • 25
  • 29
8
votes
3 answers

PHP strtotime() function that accepts a format?

strtotime() in PHP works great if you can provide it with a date format it understands and can convert, but for example you give it a UK date it fails to give the correct unix timestamp. Is there any PHP function, official or unofficial, that can…
Scott
  • 3,967
  • 9
  • 38
  • 56
8
votes
8 answers

PHP strtotime() different results of monday this week

I have a problem getting the date of monday in the current week. echo date('Y-m-d',strtotime('monday this week')); When I'm running the above code on my local machine (PHP 5.3) it outputs correctly '2011-03-07', but the same code on my server (PHP…
Stefan O.
  • 183
  • 1
  • 1
  • 4
8
votes
2 answers

Why does strtotime('x') return tomorrows date

I cant understand this - why does the following occur? echo date("d-m-Y", strtotime($str)); $str = '214454'; // Produces todays date $str = '333333'; // Produces 1-1-1970 $str = 'a' (or ANY single char) // Produces tomorrows date $str = 'aa' (or…
Laurence
  • 58,936
  • 21
  • 171
  • 212
8
votes
1 answer

How do I fix this error in PHP: "A non well formed numeric value encountered"

Possible Duplicate: A non well formed numeric value encountered Why doesn't this work? echo gmdate('Y-m-d H:i:s',strtotime('+7 days','2035-01-01 00:00:00')); The error I see is: A non well formed numeric value encountered
Jo Smo
  • 6,923
  • 9
  • 47
  • 67
7
votes
2 answers

Determine if the store is open?

In PHP and MySQL - how to determine if the Store is Open or Close (return true or false)? Also how to get the next opening hours if the store is closed? Example of Opening_Hours table: +----+---------+----------+-----------+------------+---------+ |…
user1246800
  • 287
  • 1
  • 3
  • 14
7
votes
3 answers

Advancing through relative dates using strtotime()

I'm trying to use strtotime() to respond to a button click to advance -1 and +1 days (two buttons) relative to the day advanced to on the previous click. Example: It's the 10th of the month, I click "-1 day" button, and now the date reads as the…
kevtrout
  • 4,934
  • 6
  • 33
  • 33
7
votes
3 answers

Passing a Variable in strtotime() function in PHP

Similar to this question, but there was no answer to my specific issue. The current date is 2011-12-14, for reference in case this question is viewed in the future. I tried this: $maxAge = $row['maxAge']; // for example, $row['maxAge'] ==…
Oneag
  • 93
  • 1
  • 1
  • 5
7
votes
2 answers

PHP strtotime() "first monday february" returns second monday if february 1st is a monday

I'm working on a PHP function which calculates holidays: function holidays($country = 1, $timespan_start = 0, $timespan_end = 0) The holidays are returned as timestamps in an array. Since I have to calculate dates like the first Monday of February,…
basic6
  • 3,643
  • 3
  • 42
  • 47
7
votes
7 answers

Accurate method to add months in PHP 5.1?

Yesterday I ran into an issue with PHP's strtotime not properly adding a month. On '2011-05-31' I ran: date('Y-m-d',strtotime( '+1 month', strtotime('now'))); Which returns '2011-07-01' when I am expecting '2011-06-30'. MySQL doesn't have any…
Sgraffite
  • 1,898
  • 3
  • 22
  • 29
7
votes
3 answers

Repeating Events on the "nth" Weekday of Every Month

I've looked at at least 2 dozen topics about this and haven't really found a good answer yet, so I come to you to ask once again for answers regarding the dreaded topic of Repeating Events. I've got Daily, Weekly, Monthly, and Yearly repeats working…
Eric Allen
  • 442
  • 3
  • 10
7
votes
2 answers

Is string valid for use with strtotime()?

PHP has strtotime() which assumes the input given is a string that represents a valid time. Before using strtotime(), how can I verify that the string about to be given to it is in one of its valid formats?
zmol
  • 2,834
  • 5
  • 26
  • 29
7
votes
1 answer

Why do strtotime(' ') and strtotime('.') return a timestamp?

After some messing around with strtotime() in PHP I noticed that it gives a valid timestamp back when you pass in spaces and or dots. var_dump(strtotime(" ")); var_dump(strtotime(".")); var_dump(strtotime(". .. .. .. .... .. . ..…
JurrieG
  • 93
  • 4