php strtotime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

php strtotime

Post 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>";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@work]>php -r "echo(date('m/d/Y',strtotime('next Friday 6:01pm',1128973954)));"
10/14/2005
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post 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
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

Could someone please post some tips as why the above code not returning the correct date? Thanks...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

It showing 02/11/05 09:51:54 when I ran your code at 9:51am
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post 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/>";
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post 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
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

I'm running PHP 5.0.3. Does anyone has any other explanation for this date thing? Thanks...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's a good idea to upgrade anyways.. so try it..
Post Reply