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
7
votes
5 answers

Why does PHP date('m', strtotime('-1 months')) not work correctly for today? 07/31

I have a script that gets the current and last month in PHP like so: $currentMonth = date('m'); //Expected:07 //Result:07 $lastMonth = date('m', strtotime('-1 months')); //Expected:06 //Result:07 Today happens to be the 31 or end of the month of…
Subie
  • 373
  • 2
  • 16
7
votes
2 answers

get strtotime of specific time in php

I want to get the timestamp of a day/time for eg 17/12/2014 8pm Currently I am doing $curtime = strtotime(date("Y-m-d H:i:s")); which is giving me the current timestamp but I need to be of 8pm. Any help is highly appreciated. Thanks in advance.
Raj
  • 1,377
  • 6
  • 23
  • 48
7
votes
4 answers

PHP strtotime() looks like it is expecting a Euro format

I've been using PHP's strtotime() method to accept a date field on a form. I love how powerful it is, in how it will accept "Tomorrow", "Next Thursday", or (supposedly) any date representation and convert it to the Unix timestamp. It's been working…
rhodesjason
  • 4,904
  • 9
  • 43
  • 59
7
votes
5 answers

Get dates from next week in PHP

I want to echo the dates from Mo,Tu,We,Th,Fr,Sa,Su of the next week. My code looks like this at the moment: $date_monday = date("Y-m-d", strtotime('next monday')); $date_tuesday = date("Y-m-d", strtotime('next tuesday')); $date_wednesday =…
John Brunner
  • 2,842
  • 11
  • 44
  • 85
7
votes
1 answer

setlocale(LC_ALL, 'it_IT'); set, but still dates in english

I have this code which through json_decode retrieves my latest tweets, their date, etc. "; foreach ($twitter_data as $tweet) { if…
MultiformeIngegno
  • 6,959
  • 15
  • 60
  • 119
7
votes
4 answers

How to I accurately get current UTC time via strtotime?

In PHP, how do I get the current time, in UTC, without hard coding knowledge of where my hosting provider is? For example, I tried the following: time() + strtotime('January 1, 2000')-strtotime('January 1, 2000 UTC') and find that it reports a time…
Dave
  • 83
  • 1
  • 5
6
votes
8 answers

Why does a unix timestamp need to be prefixed by '@' for strtotime() to understand it?

I noticed that strtotime() handles unix timestamps in an odd way, and I was curious if anyone knows why that is: var_export(strtotime('1330725042')); // false var_export(strtotime('@1330725042')); // 1330725042 Why does strtotime() return false…
user212218
6
votes
4 answers

Get previous month date range

I need help getting the previous months full date range in the following format: Y-m-d I have successfully been able to get "this" months full date range but not the "previous" months full date range. Any help is greatly appreciated!
three3
  • 2,756
  • 14
  • 57
  • 85
6
votes
6 answers

Why does strtotime give different result in different timezone?

I am not sure why strtotime() in PHP returns different result in different timezone even though same date is given as parameter, does anyone know the answer? I also want to know, can I do similar task (converting a datetime to an int to do…
Muhammad Usman
  • 12,439
  • 6
  • 36
  • 59
6
votes
2 answers

Bug with strtotime PHP

echo date("m", strtotime("january")); Returns 01 as expected echo date("m", strtotime("february")); But this returns 03 Anyone else encountered this problem? PHP Version 5.1.6
StefWill
  • 353
  • 1
  • 3
  • 13
6
votes
5 answers

last week, this week (php)

i am making some statistics, i want to select the time from (last week only) and this week. for this week its easy: $start = strtotime('this week'); $finish = time(); for last week $start = strtotime('last week'); $finish = ??????
TDSii
  • 1,675
  • 4
  • 20
  • 29
6
votes
3 answers

Query post_meta date instead of post_date_gmt

I'm limiting my query to use show post from 6 months ago which works fine. But I need it to be based on a date that is in the post_meta table instead of 'post_date_gmt'. In my case I have meta_keys are called payment_date and the values are of…
User_FTW
  • 504
  • 1
  • 16
  • 44
6
votes
2 answers

Comparing two timestamps in php

SO the scene is, I have a store which opens at 1:00am at night, and closes at 10:00pm. For any current time i just want to check whether that timestamp lies between store open and close times. Yeap that's very simple, and still I don't know why, am…
Sarge
  • 178
  • 1
  • 1
  • 8
6
votes
2 answers

Strange behavior with the strtotime function passing a wrong date and time format

I'm trying to understand the following behavior of the date function strtotime(): strtotime(1420066800) returns false, as expected. strtotime(1451602800) returns 26197048320! But expected false as 1451602800 is not a valid date and time format.…
Slavik Meltser
  • 9,712
  • 3
  • 47
  • 48
6
votes
1 answer

PHP get next occurrence of Monday from a certain date (with time)

I'm looking for the next Thursday after a specific date, say 2014-02-25. The problem I'm having here is that when I use the below code, the time seems to be erased.
What have you tried
  • 11,018
  • 4
  • 31
  • 45