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
-1
votes
3 answers

PHP - strtotime is ignoring the year

$date_string = "1 October, 2013"; $date_time = strtotime($date_string); //evaluates to "1412208780" $date_string_again = date("m/d/y", $date_time); //evaluates to "10/01/14" .. should be "10/01/13" Why is my code giving me the wrong year? How do I…
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
-1
votes
1 answer

strtotime() time zone warning. Storing a simple Unix Timestamp in a MySQL database with UTC Timezone

Here is the warning I get: PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and…
Dr. Dan
  • 205
  • 2
  • 11
-1
votes
2 answers

php date + strtotime returns wrong date

I have some short dates in my POST variables. If I do this: $i = 0; foreach ($data->week as $week) { $date = $_POST['date'.($i+1)]; echo $date; ... $i++; } it returns the correct short dates e.g. 09.12. and 12.12. If I do this echo…
Keith L.
  • 2,084
  • 11
  • 41
  • 64
-1
votes
3 answers

strtotime always returning 1st january

trying to have a basic time stamp next to my posts on a cms but strtotime is giving me issues. So i have this: $postDate = $row['date']; $written_month = date("F", strtotime($postDate)); $short_month = substr($written_month, 0, 3); $day_number =…
Lovelock
  • 7,689
  • 19
  • 86
  • 186
-1
votes
4 answers

strtotime() function use: error when getting result

I have this script which returns time range between 2 dates, but adding 1 day!! $date_1 = date("Y-m-d g:i:s", strtotime('2013-06-27 12:00:00')); $date_2 = date("Y-m-d g:i:s", strtotime('2013-06-29 12:00:00')); $results = array($date_1); $i =…
user2959620
  • 29
  • 1
  • 2
  • 6
-1
votes
1 answer

strftime adding +1 day also removes 5 minutes

Somehow, using strtotime and adding "+1 day" not only adds the day, but also removes 5 minutes. In the following example I expect '2013-10-02 08:15:00', but get '2013-10-02 08:10:00': $myDate = '2013-10-01 08:15:00'; $newDate = strtotime($myDate . '…
Dave
  • 28,833
  • 23
  • 113
  • 183
-1
votes
5 answers

Create a loop that will increment time by one hour

I've spent so much time on trying to figure out how to create a loop that will echo time between given $start_time and $end_time incrementing it by one hour in format HH:MM. For example if i have $start_time = "09:00" and $end_time="15:00" the…
lolka
  • 5
  • 1
  • 5
-1
votes
2 answers

PHP strtotime weird behaviour

This code was working fine until yesterday: $fechaactual = strtotime('now'); $timestamp = strtotime($v->startDate); $pelo = date("d/m G:i:s",$fechaactual); $pelo2 = date("m/d G:i:s",$timestamp); $timestamp = strtotime($pelo2); $timestamp2 =…
-1
votes
1 answer

Using strtotime and date to add time to date

I am having an incredibly hard time understanding strtotime even after reading the never ending questions on stack overflow on the subject.... date('Y-m-d',strtotime("+3 months",date('Y-m-d'))) Why does that not return 2013-10-09 (given today's…
Hydra IO
  • 1,537
  • 1
  • 13
  • 28
-1
votes
2 answers

How to get the next 0900 date/time in PHP?

I need to get the next 0900 date in PHP. For example: If it is 0859 right now, the next 0900 is today at 0900 If it is 0901 right now, the next 0900 is tomorrow at 0900 I'm only interested in the date in yyyymmdd format. Any suggestions on how to…
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
-1
votes
2 answers

PHP strtotime returning false

Below is the output from a database and I am trying to get the number of months between the start date and the date from the database. Below is my output string(10) "12/12/2010" Date : 12/12/2010 - 1292112000 string(10) "19/04/2000" Date :…
roadkill247
  • 213
  • 1
  • 5
  • 12
-1
votes
1 answer

PHP upcoming First Friday of the month

(Moved to Code Review, where this belongs). I have an event recurring on the first friday of the month (at 7pm), and I need to output the date of the next first friday coming up. This is the first bit of PHP I've written, and I was wondering if…
-1
votes
1 answer

PHP: Can't Convert MySQL DateTime to Epoch (with Correct Time of Day)

I'm grabbing a datetime from a MySQL database using php. In mysql the datetime looks like this: '2004-11-03 06:29:48' The line of my code that get the datetime from the database looks like this: $epochTime = strtotime($row[8]); Php's strtotime…
Lonnie Best
  • 9,936
  • 10
  • 57
  • 97
-1
votes
2 answers

Why strtotime returns false?

if(strtotime($date_in)==false){ echo $date_in." wtf?"; } Output: 2012-05-12 wtf? Why does strtotime($date_in) return false?
szapio
  • 998
  • 1
  • 9
  • 15
-1
votes
2 answers

Get which day of the week the month starts on for given input

I have a function which defines what day of the week the month starts on for the current month: public function firstDayOfMonth() { $day = (int) date("w", strtotime(date('m').'/01/'.date('Y').' 00:00:00')); return $day; …
RSM
  • 14,540
  • 34
  • 97
  • 144