Page 1 of 1

php strtotime

Posted: Tue Nov 01, 2005 8:15 am
by quadoc
I'm trying to get the "next Friday at 6:01pm" for a timestamp, but some how it doesn't seem to work. Could someone please tell me why and post some tips. Thanks... :?

Code: Select all

$date = "1128973954"; 
$newdate = date("m/d/Y",strtotime($date." next Friday 6:01pm")); 
  echo "Next Friday from ".$date." is=".$newdate."<br>";

Posted: Tue Nov 01, 2005 8:33 am
by feyd

Code: Select all

[feyd@work]>php -r "echo(date('m/d/Y',strtotime('next Friday 6:01pm',1128973954)));"
10/14/2005

Posted: Tue Nov 01, 2005 9:01 am
by quadoc
Something's weird is happening with my code below. It returned one week more than it should. Please see code

Code: Select all

$datei = "1128973954";  $datea = date("m/d/Y g:i a",$datei);
$newdate = date("m/d/Y g:i a",strtotime('next Friday 6:01pm',$datei)); 

echo "**next Friday from".$datea." is ".$newdate."<br>";
String output:
Next Friday from 10/10/2005 3:52 pm is=1129932060, which is=10/21/2005 6:01 pm

Posted: Wed Nov 02, 2005 7:40 am
by quadoc
Could someone please post some tips as why the above code not returning the correct date? Thanks...

Posted: Wed Nov 02, 2005 8:19 am
by feyd
you have a screwy server

Code: Select all

[feyd@work]>php -r "$datei = 1128973954; $datea = date('m/d/Y g:i a D',$datei); $newdate = date('m/d/Y g:i a D',strtotime('next Friday 6:01pm',$datei)); echo $datea.chr(13).$newdate;"
10/10/2005 7:52 pm Mon
10/14/2005 6:01 pm Fri

Posted: Wed Nov 02, 2005 8:29 am
by quadoc
I think my server is screwy too. 8O In this case what kind of setting should check for? Anything in the php.ini file need to be looked at? Thanks for the tips.

Posted: Wed Nov 02, 2005 8:44 am
by Jenk
Does the following print the correct date/time?

Code: Select all

<?php

echo date("d/m/y H:i:s", time());

?>
If it doesn't, contact server provider and get them to change the clock.

Posted: Wed Nov 02, 2005 8:53 am
by quadoc
It showing 02/11/05 09:51:54 when I ran your code at 9:51am

Posted: Fri Nov 04, 2005 10:58 am
by quadoc
Interesting thing that I've found out. If you replace the "next Friday" with just "Friday" you will get a different result. :)

Code: Select all

$datei = 1128973954; $datea = date('m/d/Y g:i a D',$datei);
$newdate = date('m/d/Y g:i a D',strtotime('next Friday 6:01pm',$datei)); 

echo date("m/d/y H:i:s", time())."<br/>"; 
echo $datea."<br/>";
echo $newdate."<br/>";

Posted: Fri Nov 04, 2005 11:28 am
by yum-jelly
What version of PHP are you running? I know this happened to a few people on the PHP mailing list. But if I recall it was only in one or two versions over a snaps.php.net and then it was fixed! I got a funny release the other day all the $_SERVER varaibles would not work with a right * ] *, fatal error, when I views the array it looked like this...

Code: Select all

Array (
[HTTP_HOST => ....
[HTTP_PORT => ....
);
funny stuff! Maybe you should try a different release to see if it goes away!


yj

Posted: Mon Nov 07, 2005 8:19 am
by quadoc
I'm running PHP 5.0.3. Does anyone has any other explanation for this date thing? Thanks...

Posted: Mon Nov 07, 2005 8:31 am
by feyd
well... you could probably do it via your own calculations.. not all that hard... just find out what day of the week it is from date() then simply snap to Friday..

Posted: Mon Nov 07, 2005 8:42 am
by quadoc
yes, I know. But since php has this feature why not let it do all the work. :) I just want to know if this is a bug with php 5.0.3, if it is I will upgrade to a newer version.

Posted: Mon Nov 07, 2005 8:43 am
by feyd
it's a good idea to upgrade anyways.. so try it..