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

`strtotime` bug when using + 1 month from January

I' m trying to make a ajax calendar with multiple tabs for a date range previously entered. But for example: I want get the next month, it prints march instead of february $start= "2013-01-31"; $current = date('n', strtotime("+1 month",$start))…
4
votes
3 answers

strtotime and DateTime giving wrong year when parsing a year

$year = date('Y', strtotime("2012")); var_dump($year);//returns 2013 This is happening with an old server with php 5.2 and a new one with php 5.4 The server uses strtotime to get the year from a string like 2012-01-01 or 2012-01 or 2012 I also…
Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143
4
votes
3 answers

strtotime for Emacs Lisp

Is there any functionality in Emacs Lisp that behaves similar to PHP's strtotime function? (Actually AFAIK it implements relative items of the GNU date input formats.) In PHP I can write echo strtotime("+2 months"); //1258891352 echo strtotime("-3…
viam0Zah
  • 25,949
  • 8
  • 77
  • 100
4
votes
3 answers

Strange behavior of Date Function

I encountered with this question today on StackOverflow but didn't get answer. My question is echo date('Y-m-d',strtotime('2012-september-09')); // output - 2012-09-01 echo date('Y-m-d',strtotime('09-september-2012')); // output -…
Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59
4
votes
3 answers

PHP strtotime() outputs nothing

Here is my PHP code: echo '
1. '.$w_time_no; echo '
2. '.strtotime($w_time_no); echo '
3. '.date('G:i', strtotime($w_time_no)); That's what I get: 1. 0000-00-00 22:00:00 2. 3. 2:00 Why strtotime() outputs nothing by itself? Is there…
user150007
4
votes
1 answer

Get the last Thursday, but only if it's the second Thursday in this sequence

I know I can get the last Thursday with this $firstdate = strtotime('last thursday'); However, as of the time posting this question it will return August 2nd, 2012 What I need is the last Thursday that follows this two week cycle: August 9…
Bobby S
  • 4,006
  • 9
  • 42
  • 61
4
votes
2 answers

Get month after and before given month name

How do I get the month name after a given month. So for June, I would want July I have tried: $next_month = date('F',strtotime('June', "next month")); This display January, which is obviously wrong, I am looking for July. How would I then get the…
RSM
  • 14,540
  • 34
  • 97
  • 144
3
votes
2 answers

PHP Regular Expression to Change Date Format

I almost tried for 10 hours to change the date format suits my needs but couldn't success. I have tried Preg_Replace Strotime functions with following examples. The current date format is : 02-25-2006 Want to convert to: 2006-02-25 Here are the list…
Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110
3
votes
5 answers

strtotime returns current year when input is in the format of YYYY and the value is greater then 1999

I'm not sure that this is a bug since after searching I can't find any duplicate experiences- however, this one has me stumped. While in the midst of a (rather painful) script that is intended to take a bunch of freetext records and convert them to…
cailen
  • 33
  • 1
  • 3
3
votes
4 answers

php, date() not returning the right date/time

The code below... $date = "02-13-2012"; $start_time = "17:30"; $end_time = "20:00"; $start_timestamp = date("m-d-Y H:i",strtotime($date." ".$start_time)); $end_timestamp = date("m-d-Y H:i",strtotime($date."…
Brook Julias
  • 2,085
  • 9
  • 29
  • 44
3
votes
2 answers

php strtotime "last friday April 2012" not returning last friday

When I run the following code, I get the 30th of April rather than the 27th. strtotime("Last Friday April 2012"); I tried running it as a Thursday instead and I got back the 29th. All the following work fine. strtotime("First Sunday February…
NRoscoe
  • 33
  • 5
3
votes
6 answers

Convert MMDDYYYY to date for PHP

I have a string with a date which is in this format MMDDYYYY (ie. 01132012, 01142012 etc.) I need to do something on a page, if that string is 14 days or less from the current date. ie. Today is 01132012, so any strings with 12312011 or a less date…
jsquadrilla
  • 265
  • 1
  • 7
  • 17
3
votes
3 answers

how is the best method create simply calendar?

how is the best method create simply calendar? i have for example in db: id | date(unique)| text 1 | 2011-02-02 | aaa 2 | 2011-03-03 | bbb 3 | 2011-03-04 | ccc .. 10 | 2011-03-11 | dfg for example now is 2011-03-04. i would like get from…
3
votes
1 answer

New way of defining timestamp in PHP 5.3?

Is there a new approach in PHP 5.3 to define timestamp? this strtotime('0000-00-00'); will return 0 date(01/01/1970) in PHP prior 5.3 and -62169984000 in PHP 5.3. And a date like 30/11/-0001 !! But I could not find any explanations about that in the…
Yasen Zhelev
  • 4,045
  • 3
  • 31
  • 56
3
votes
0 answers

strtotime function for year 2022 First Friday not working

For year 2022 the strtotime "first Friday" query does not work when first Friday is first day of month. E.G. For 2022 month equal 7: $result = date("Y-n-j", strtotime('first Friday 2022-7'); returns string equal 2022-7-8 vs 2022-7-1. For the "first…