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
22
votes
2 answers

PHP strtotime: Get previous month

Possible Duplicate: How to get previous month and year relative to today, using strtotime and date? Today is December, 31st but strtotime("-1 months") returns December: echo date("Y-m", strtotime("-1 months")); Same for strtotime("last…
Martin
  • 2,007
  • 6
  • 28
  • 44
21
votes
8 answers

Determine If Business Is Open/Closed Based On Business Hours

My code works fine if the times are AM to PM (Ex: 11 AM - 10 PM), but if the locations hours of operation are AM to AM (Ex: 9 AM - 1 AM) it breaks. Here is my code: $datedivide = explode(" - ", $day['hours']); //$day['hours'] Example 11:00 AM -…
Stephen
  • 707
  • 3
  • 13
  • 33
19
votes
2 answers

Check if timestamp is x hours old?

Simple question, but I couldn't find any related topics that match this exact scenario. Everything I found involved MySQL or date and time rather than just time. I have a timestamp stored in a variable in the format of: 1325960262 Produced by:…
tctc91
  • 1,343
  • 2
  • 21
  • 41
19
votes
8 answers

PHP strtotime +1 month behaviour

I know about the unwanted behaviour of PHP's function strtotime For example, when adding a month (+1 month) to dates like: 31.01.2011 -> 03.03.2011 I know it's not officially a PHP bug, and that this solution has some arguments behind it, but at…
Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
19
votes
10 answers

php function for get all mondays within date range

Example: $startDate is Monday 2007-02-05 and $endDate is Tuesday 2007-02-20. Then I want it to list: Monday 2007-02-05 Monday 2007-02-12 Monday 2007-02-19 I looked at the PHP manual and found this to get all the days between two dates. But how to…
Nisha
  • 385
  • 2
  • 3
  • 5
18
votes
1 answer

PHP, use strtotime to subtract minutes from a date-time variable?

I need to subtract 45 minutes from the date-time variable in PHP. The code: $thestime = '2012-07-27 20:40'; $datetime_from = date("Y-m-d h:i",strtotime("-45 minutes",strtotime($thestime))); echo $datetime_from; returns the result 2012-07-27 07:55. …
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217
16
votes
3 answers

PHP strtotime() function wrong by 1 hour?

I am converting dates and times into timestamps using PHP before they are inserted into my MySQL database. My problem is that when i use PHP's strtotime function the output timestamp is -1 hour behind my actual time. For example, considering todays…
David
  • 163
  • 1
  • 1
  • 4
16
votes
2 answers

php get microtime from date string

I am trying to get the time passed between two datetime strings (including milliseconds) example: $pageTime = strtotime("2012-04-23T16:08:14.9-05:00"); $rowTime = strtotime("2012-04-23T16:08:16.1-05:00"); $timePassed = $rowTime - $pageTime; echo…
slinkhi
  • 947
  • 4
  • 16
  • 32
15
votes
4 answers

PHP date() and strtotime() return wrong months on 31st

I'm using date()and strtotime() functions to display the next 3 months in a dropdown list. PHP Code: echo date("m/Y",strtotime("+0 months")); echo date("m/Y",strtotime("+1 months")); echo date("m/Y",strtotime("+2 months")); However, if…
Michael Wu
  • 293
  • 1
  • 4
  • 13
15
votes
3 answers

How to get date from week number & day number and year?

I'm trying to get the date from the week number, day number and year. For eg: week number = 52 day number = 4 (of week 52) year = 2013 In this case, the date should be 26-12-2013. How can I do it using PHP? I've already tried with…
Code
  • 1,574
  • 2
  • 23
  • 37
15
votes
3 answers

PHP check if timestamp is greater than 24 hours from now

I have software that needs to determine if the cutoff datetime is greater than 24 hours from now. Here is the code I have to test that. $date = strtotime("2013-07-13") + strtotime("05:30:00"); if($date > time() + 86400) { echo 'yes'; } else…
Naterade
  • 2,635
  • 8
  • 34
  • 54
15
votes
6 answers

PHP Strtotime -1month -2month

This was working fine yesterday with no changes to the code. echo date("M", strtotime("-3 month", time()) ); echo date("M", strtotime("-2 month", time()) ); echo date("M", strtotime("-1 month", time()) ); echo date("M", time()); The output it was…
bcmcfc
14
votes
3 answers

PHP - Using strtotime with a UK date format (dd-mm-yy)

Quite simply in PHP I have a date of 8th January 2011, in the format 08-01-11 - when I run this into strtotime and convert it back into a different date format, it reverts back to 1st August 2011 - not ideal! Is there any easy way around this,…
Nick
  • 1,233
  • 13
  • 26
  • 37
14
votes
10 answers

php check for a valid date, weird date conversions

Is there a way to check to see if a date/time is valid you would think these would be easy to check: $date = '0000-00-00'; $time = '00:00:00'; $dateTime = $date . ' ' . $time; if(strtotime($dateTime)) { // why is this valid? } what really gets…
SeanDowney
  • 17,368
  • 20
  • 81
  • 90
14
votes
7 answers

PHP - Strtotime - Add hours

I have this variable: $timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time ()); I simply want to add three hours and echo it out. I have seen the way where you can do the 60 * 60 * 3 method or the hard code "+ 3 hours" where it understands the…
TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259
1 2
3
87 88