strtotime

php check for a valid date, weird date conversions

Is there a way to check to see if a date/time is valid you would think these would be easy to check: $date = '0000-00-00'; $time = '00:00:00'; $dateTime = $date . ' ' . $time; if(strtotime($dateTime)) { // why is this valid? } what really gets me is this: echo date('Y-m-d', strtotime($date)); results in: "1999-11-30", huh? i ...

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 more clever way of doing it. ...

How can I offset system time to test my PHP function?

I'm writing a function that works out whether or not the time is between 9am and 5pm on a working day. It then tells you when the next working day starts (if currently out of business hours) based on whether today's business hours have ended or (if after midnight) are about to begin. All is going well so far, and to create the most rea...

remove 5 hours from the time

I'm using strtotime to create a timestamp from some ropey XML, but the timezone is incorrect. How can I remove 5 hours from the time? ...

Backward-counting day display in php

I am a complete newbie in PHP. I would like to show the number of days missing for a specific date. In other words, I want to display something like: "X days to go for the great event" using PHP and the server time. How is this accomplished? ...

PHP Strtotime -1month -2month

Hi, This was working fine yesterday with no changes to the code. echo date("M", strtotime("-3 month", time()) ); echo date("M", strtotime("-2 month", time()) ); echo date("M", strtotime("-1 month", time()) ); echo date("M", time()); The output it was producing yesterday was as you would expect- i.e. Apr, May, Jun, Jul Today it echoe...

PHP strtotime() outputs nothing

Here is my PHP code: echo '<br />1. '.$w_time_no; echo '<br />2. '.strtotime($w_time_no); echo '<br />3. '.date('G:i', strtotime($w_time_no)); That's what I get: 1. 0000-00-00 22:00:00 2. 3. 2:00 Why strtotime() outputs nothing by itself? Is there something wrong with server settings? Server: Apache/2.2.11 (Win32), PHP 5.2.10, MySQ...

PHP's strtotime() in Java

strtotime() in PHP can do the following transformations: Inputs: strtotime(’2004-02-12T15:19:21+00:00′); strtotime(’Thu, 21 Dec 2000 16:01:07 +0200′); strtotime(’Monday, January 1st’); strtotime(’tomorrow’); strtotime(’-1 week 2 days 4 hours 2 seconds’); Outputs: 2004-02-12 07:02:21 2000-12-21 06:12:07 2009-01-01 12:01:00 2009-02-...

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 do a certain task only 30 minutes within his endTime. After 30 minutes of his endTime, ...

PHP: strtotime()... again.

How do I have to write "+3 days at 12:34:56" to make strtotime() parse it properly? ...

strtotime for Emacs Lisp

Is there any functionality in Emacs Lisp that behaves similar to PHP's strtotime function? (Actually AFAIK it implements relative items of the GNU date input formats.) In PHP I can write echo strtotime("+2 months"); //1258891352 echo strtotime("-3 months +2 weeks"); //1246952239 which return the corresponding UNIX timestamps. ...

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 that is one hour ahead of actual UTC time. I tried this on two different hosting prov...

Coldfusion equiv of PHP strtotime() ?

I'm relatively new to CF / Flex3 and I've been tasked with making mock applications in order to get my knowledge of the 2 languages up. I'm creating an application where I require data back 1 week (strtotime equiv '-1 week'). So that the result is always 1 weeks worth. Whats the comparable equivalent if any for coldfusion? If none, h...

PHP: strtotime() gives me wrong timestamp

This is my code: $testtime = str_replace('.', '-', '2009.07.08 17:01'); $timestamp = strtotime($testtime); echo $timestamp . "\n"; echo $testtime . "\n"; echo date('Y-m-d H:t', $timestamp); And this is my output: 1247065260 2009-07-08 17:01 2009-07-08 17:31 What's wrong? Thank you in advance. ...

correct arguments format for strtotime

Hi, I've been using strtotime("$day-$month-$year"), in my app and it works cool... but know I want to make some date comparisons still in this format but I'm not sure about what is precise, It's as if any format goes ...

php strtotime is choking on time zone string

<?php echo "Hello?"; $thetime = strtotime("Wed Dec 16 2009 00:00:00 GMT-0500 (Eastern Standard Time)"); var_dump($thetime); ?> This code evaluates to "bool(false)"; however, just removing "(Eastern Standard Time)" allows the strtotime function to evaluate correctly. Any ideas why strtotime is choking on the time zone bit of the str...

PHP: $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? Thanks! ...

Why is strtotime($lastmoment) bigger than time()?

The following code echo $lastmoment."<br/>"; echo time(); echo "<br/>"; echo strtotime($lastmoment); outputs: 2009-12-15 17:40:53 1260876829 1260898853 What's wrong? $lastment is a past time stamp in MySQL, why is strtotime($lastmoment) bigger than time()? ...

Adding days to specific day

Many examples are about adding days to this day. But how to do it, if I have different starding day? For example (Does not work): $day='2010-01-23'; // add 7 days to the date above $NewDate= Date('$day', strtotime("+7 days")); echo $NewDate; Example above does not work. How should I change the starding day by putting something else ...

Make strtotime() generate times only in the future.

I'm trying to make a PHP script to find the next occurence of a date (say 5-1). However, if I put that into strtotime() on 5-2 it comes up with the date from this year. I simply want to make it always return the next date possible. How can I make this work? I'm using codeigniter if that helps. EDIT: Here's some code I came up with, if s...