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

Why is strtotime() giving the wrong date?

I'm using the following code $t = strtotime('Saturday, 28 Dec, 2013'); echo date('d/m/Y H:i',$t); // output : 03/01/2015 20:13 $t = strtotime('Wednesday, 01 Jan, 2014'); echo date('d/m/Y H:i',$t); // output: 01/01/2014 20:14 The first example…
anhduc.bkhn
  • 695
  • 3
  • 10
  • 21
6
votes
6 answers

STRTOTIME to find current week, date for Monday and Saturday, PHP

I have these lines: $staticstart = date('Y-m-d',strtotime('last Monday')); $staticfinish = date('Y-m-d',strtotime('next Saturday')); And I am using them to select the monday and saturday of the current week, But when it is actually Monday, it…
atomapps
  • 183
  • 1
  • 3
  • 13
6
votes
2 answers

PHP - using date to find out daylight savings time

I want to give date() a date and have it return if that date is DST or not. Running PHP 5.4.7 via xampp on a windows 7 box. A linux box running PHP 5.2.8 returns 0 no matter what date I give it. What's wrong with my code? echo date('I',…
user2001487
  • 453
  • 4
  • 14
6
votes
5 answers

php strtotime does not work

I got an issue on below script, assume $exp_date is retrieved from db, I want to compare expiry date with today date to check whether membership's is still alive. There is nothing to display but only Time Expired, what's wrong with the code? The…
conmen
  • 2,377
  • 18
  • 68
  • 98
6
votes
4 answers

php string in a date format, add 12 hours

I have this string object in my php array "2013-03-05 00:00:00+00" I would like to add 12 hours to the entry within PHP, then save it back to string in the same format I believe this involves converting the string to a date object. But I'm not sure…
CQM
  • 42,592
  • 75
  • 224
  • 366
6
votes
2 answers

Convert strtotime() to StrFTime()

I was asked to write a module for our billing system and completed it using all of the functions I am accustomed to. It was tested on an English setup, but I did not take into account (nor was I aware of) the fact the actual system our company uses…
user470760
6
votes
3 answers

Computing relative dates in php using strtotime()

I'm looking for a reliable way to return the full date of a specified weekday (e.g. "Mon") for the current week. Since today is Wednesday, June 13, 2012, I expected to result in 2012-06-11,…
jalperin
  • 2,664
  • 9
  • 30
  • 32
6
votes
3 answers

Get timestamp from date('z') and year

I know the year and the day of year (0-365). Is there any way to get back from it to timestamp? Something like: $day=date('z'); $year=2012; $timestamp=strtotime($day.'-nd day of '.$year);
Narek
  • 3,813
  • 4
  • 42
  • 58
5
votes
4 answers

php: strtotime("12/31/2004 +6 month")); not returning the last day of June

I expected this functional to return 6/30/2005 instead of 7/1/2005. print date("m/d/Y", strtotime("12/31/2004 +6 month")); Similarly, print date("m/d/Y", strtotime("1/31/2011 +1 month")) returns 03/03/2011 while would like it to return…
user1042425
  • 51
  • 1
  • 3
5
votes
6 answers

strtotime equivalent in .NET

Is there an equivalent of PHP's strtotime() function working on .NET Framework. I'm talking about it's capacity to handle strings likes: strtotime("now") strtotime("10 September 2000") strtotime("+1 day") strtotime("+1 week") strtotime("+1 week 2…
Wernight
  • 36,122
  • 25
  • 118
  • 131
5
votes
3 answers

string to time over 24 hour in php

There is a synatax errro your variable name is $hour but in last you have used $hours. $time1 = strtotime("02:40:00"); $time2 = strtotime("34:20:00"); $diff = $time2 - $time1; $hour = floor($diff / (60 * 60)); $minute = $diff - $hour * (60 *…
Ifadak
  • 65
  • 11
5
votes
2 answers

strtotime and date not outputting correctly

I am having trouble echoing out the correct unix timestamp for the date saved in the database. $activeWorkRow['WorkDate'] = "9/24/2015 1:45:53 PM"; $locateDate = $activeWorkRow['WorkDate']; $locateDate = str_replace('/', '-',…
John Lang
  • 85
  • 1
  • 7
5
votes
2 answers

php first and last weekday (workable Mon-Fri) of month using simple strtotime

Solved! i leave it here for you. This two lines of code are ok for the first workable day: date('d-m-Y',strtotime('+0 weekdays October 2016')) Returns : 3-10-2016 --> OK date('d-m-Y', strtotime('weekday february 2016')) Returns : 1-2-2016 …
Jonathan Orrego
  • 131
  • 2
  • 6
5
votes
3 answers

Converting date (with milliseconds) into timestamp

I have date format like '25 May 2016 10:45:53:567'. I want to convert into the time stamp. strtotime function returns empty. $date = '25 May 2016 10:45:53:567'; echo strtotime($date); // returns empty When I removed the milliseconds, it's…
Tamilvanan
  • 708
  • 1
  • 7
  • 21
5
votes
2 answers

Store date of birth in database as UNIX time?

I want to store the date of birth as a UNIX timestamp in my database, because this keeps the database small and it speed up the queries. However, when converting the date of birth to a UNIX time using strtotime, it will output the wrong value,…
Piet
  • 2,188
  • 5
  • 19
  • 30