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

What is first weekday in PHP's strtotime()?

strtotime() in PHP is quite powerfull function. One of it's features is relative dates. For example this command: echo date('Y-m-d', strtotime('Sunday this week')); produces 2016-02-14 on my machine (today is "2016-02-12", Friday). Thus it supposes…
Stalinko
  • 3,319
  • 28
  • 31
4
votes
1 answer

php: strtotime how to get last july? (or other specific month)

if now is 2016-02-10 I need for return 2015-07-01 (or 2015-07-10) strtotime('july'); // returns 2016-07-10 strtotime('last july'); // does not work strtotime('july 2015'); // I have not '2015' for query. //Only if compare date (month) now and month…
scrache
  • 113
  • 1
  • 1
  • 8
4
votes
3 answers

Auto generate year based on future date

I have a date string formatted as March 8 - 10 where the year is not provided, but based on the current day of the calendar year, this would be dates in March of the next year. What is best approach to provide the accurate year when a date given…
RonnieT
  • 2,193
  • 4
  • 32
  • 43
4
votes
2 answers

PHP - Get difference between two datetime in seconds

I have a datetime value I want the difference between that datetime and datetime now .. I tried to convert it to timestamp and calculate the difference but I got a negative value. How to get the difference in seconds ?
user3003810
  • 941
  • 3
  • 18
  • 45
4
votes
2 answers

PHP: parsing a date of any format (especially: 2008-10-20, 2008/10/20, 2008.10.20, Nov. 20/08)

strtotime("25/03/1957") returns false. what will satisfy all of these date formats? i can't imagine how long it would take to actually make my own, so i hope there's already one out there you know of. thanks!
Garrett
  • 11,451
  • 19
  • 85
  • 126
4
votes
3 answers

PHP date problem

I have web service in PHP which gets dateTime object (from asp) . I want to parse this date in my custom format . The date originally is in format "2010-07-05T00:00:00+02:00" . When I'm trying this: $oDate = strtotime($date_from_webservice); $sDate…
user345602
  • 578
  • 1
  • 12
  • 26
4
votes
1 answer

Advice for php time zone settings

I live in Denmark - but am setting up a page for a friend in USA (Washington State). The page is hosted at Surftown, in Denmark. I know there is a 9 hour difference, so I set: date_default_timezone_set('America/Los_Angeles'); But there is something…
4
votes
1 answer

Usage of 'next' in strtotime with multiple relative dates

After looking at the PHP.NET Relative Format Dates page, I'm still confused about the order of operations with multiple relative dates in strtotime when subtracting. I've noticed that the following returns 1/9/2015. strtotime('next friday -7 days',…
scottheckel
  • 9,106
  • 1
  • 35
  • 47
4
votes
4 answers

PHP adding AM/PM to a time string

I'm getting a time value from a database call in the following format: HH:MM:SS Here are some examples: 08:15:00 22:45:00 I need to however convert these and display them, using the above examples, as follows: 8:15 AM 10:45 PM and so on. I've…
user982124
  • 4,416
  • 16
  • 65
  • 140
4
votes
4 answers

PHP strtotime( YYYY-mm last day) a month off error

I'm trying the following command in PHP 5.2.12 : print (date('Y-m-d', strtotime('2009-12 last day'))); Regarding to the php.net manual : date('m/d/y', strtotime('2009-03 last day')); # 03/31/09 it should display the last day of march 2009…
Kami
  • 5,959
  • 8
  • 38
  • 51
4
votes
3 answers

Start and end time, split into 1 hour segments

I have a start and end time in a timestamp format. I want to split these into timeslots of e.g 1 hour. $t1 = strtotime('2010-05-06 12:00:00'); $t2 = strtotime('2010-05-06 18:00:00'); $timeslots = array(); while ($t1 < $t2) { $t1 = $t1 + 3600; …
deadlyhifi
  • 577
  • 5
  • 15
4
votes
3 answers

Php: Add variable amount days to Y-m-d date format

i'm trying to add days to a date with the 'Y-m-d' format: $oldDate = '2013-05-15'; $newDate = date('Y-m-d', strtotime($oldDate. " + 5 days")); This ouputs '2013-5-20', but below: $oldDate = '2013-05-15'; $addedDays = 5; $newDate = date('Y-m-d',…
muffin
  • 2,034
  • 10
  • 43
  • 79
4
votes
2 answers

php - mktime or strtotime?

I'm trying to convert 2010-02 to February, 2010. But, I keep getting December, 1969 I've tried using mktime, strtotime, and some combination of the two, but still haven't been able to do it... This is what I tried most recently... $path_title =…
n00b0101
  • 6,863
  • 17
  • 42
  • 36
4
votes
2 answers

Why do strtotime() and date() return 1969-31-12?

I have this code: $endDate='02-20-2014'; //Just updated this echo date('Y-d-m',strtotime($endDate)); Why does strtotime() keeps giving me 1969-31-12? My goal is to get: 2014-02-20
Sean Bray
  • 71
  • 1
  • 5
4
votes
4 answers

Add minutes to strtotime

If i have a varible // in minutes $min = 40; And i want to add it to a strotime formatted time $strtTime = $strtotime('now') + $min; whats the correct way to do this?
Shawn Sonnier
  • 513
  • 5
  • 10
  • 28