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
116
votes
14 answers

$date + 1 year?

I'm trying to get a date that is one year from the date I specify. My code looks like this: $futureDate=date('Y-m-d', strtotime('+one year', $startDate)); It's returning the wrong date. Any ideas why?
Matt
  • 7,022
  • 16
  • 53
  • 66
110
votes
11 answers

Adding three months to a date in PHP

I have a variable called $effectiveDate containing the date 2012-03-26. I am trying to add three months to this date and have been unsuccessful at it. Here is what I have tried: $effectiveDate = strtotime("+3 months",…
user979331
  • 11,039
  • 73
  • 223
  • 418
110
votes
10 answers

PHP, Get tomorrows date from date

I have a PHP date in the form of 2013-01-22 and I want to get tomorrows date in the same format, so for example 2013-01-23. How is this possible with PHP?
Justin
  • 42,716
  • 77
  • 201
  • 296
92
votes
12 answers

Given a Unix timestamp, how to get beginning and end of that day?

I have a Unix timestamp like this: $timestamp=1330581600 How do I get the beginning of the day and the end of the day for that timestamp? e.g. $beginOfDay = Start of Timestamp's Day $endOfDay = End of Timestamp's Day I tried this: $endOfDay =…
Talon
  • 4,937
  • 10
  • 43
  • 57
70
votes
15 answers

How to get previous month and year relative to today, using strtotime and date?

I need to get previous month and year, relative to current date. However, see following example. // Today is 2011-03-30 echo date('Y-m-d', strtotime('last month')); // Output: 2011-03-02 This behavior is understandable (to a certain point), due to…
mr.b
  • 4,932
  • 11
  • 38
  • 55
61
votes
6 answers

adding 30 minutes to datetime php/mysql

I have a datetime field (endTime) in mysql. I use gmdate() to populate this endTime field. The value stored is something like 2009-09-17 04:10:48. I want to add 30 minutes to this endtime and compare it with current time. ie. the user is allowed to…
someisaac
  • 1,027
  • 1
  • 11
  • 13
59
votes
10 answers

PHP: How to check if a date is today, yesterday or tomorrow

I would like to check, if a date is today, tomorrow, yesterday or else. But my code doesn't work. Code: $timestamp = "2014.09.02T13:34"; $date = date("d.m.Y H:i"); $match_date = date('d.m.Y H:i', strtotime($timestamp)); if($date == $match_date) {…
R2D2
  • 743
  • 1
  • 7
  • 14
50
votes
7 answers

Adding 30 minutes to time formatted as H:i in PHP

Having a nightmare at the moment and just can't see why it isn't working I have a value in the form H:i (ie 10:00, 13:30) etc called $time What I want to do is create two new values, $startTime which is 30 mins before $time and $endTime which is 30…
bateman_ap
  • 1,911
  • 7
  • 28
  • 41
48
votes
7 answers

Working days (Mon-Fri) in PHP

Is there a way to use strtotime to add working days (Monday to Friday) to a date? Or some other method? What I want to do is: date ( 'Y-m-j' , strtotime ( '+3 working days' ) )
fredley
  • 32,953
  • 42
  • 145
  • 236
47
votes
9 answers

PHP Check if current time is before specified time

I need to check in PHP if the current time is before 2pm that day. I've done this with strtotime on dates before, however this time it's with a time only, so obviously at 0.00 each day the time will reset, and the boolean will reset from false to…
Adam Moss
  • 5,582
  • 13
  • 46
  • 64
46
votes
8 answers

php strtotime "last monday" if today is monday?

I want to use strtotime("last Monday"). The thing is, if today IS MONDAY, what does it return? It seems to be returning the date for the monday of last week. How can I make it return today's date in that case?
Nathan H
  • 48,033
  • 60
  • 165
  • 247
43
votes
2 answers

What is a Unix timestamp and why use it?

What is a Unix timestamp? In PHP, when working with dates, the function strtotime() outputs some integer value -- what is that? I tried to learn about this but I couldn't get satisfactory answer, especially why do we need to convert dates using…
user3073602
42
votes
9 answers

Simplest way to increment a date in PHP?

Say I have a string coming in, "2007-02-28", what's the simplest code I could write to turn that into "2007-03-01"? Right now I'm just using strtotime(), then adding 24*60*60, then using date(), but just wondering if there is a cleaner, simpler, or…
davr
  • 18,877
  • 17
  • 76
  • 99
40
votes
4 answers

PHP Converting Integer to Date, reverse of strtotime

"; // output is 1388516401 ?> I am surprised if it can be reverse. I mean can I convert 1388516401 to 2014-01-01 00:00:01. What I actually want to know is, what's the logic behind this conversion.…
Wasim A.
  • 9,660
  • 22
  • 90
  • 120
40
votes
3 answers

Check if variable is a valid date with PHP

I am working on a script that will import some data from a CSV file. As I am doing this I want to be able to check a variable to see if it is a valid date string. I have seen several ways to check if a sting is a date, but most of them require you…
Alex
  • 1,535
  • 2
  • 16
  • 26
1
2 3
87 88