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
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Tue Nov 01, 2005 8:15 am
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>";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Nov 01, 2005 8:33 am
Code: Select all
[feyd@work]>php -r "echo(date('m/d/Y',strtotime('next Friday 6:01pm',1128973954)));"
10/14/2005
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Tue Nov 01, 2005 9:01 am
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
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Wed Nov 02, 2005 7:40 am
Could someone please post some tips as why the above code not returning the correct date? Thanks...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 02, 2005 8:19 am
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
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Wed Nov 02, 2005 8:29 am
I think my server is screwy too.
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.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Wed Nov 02, 2005 8:44 am
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.
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Wed Nov 02, 2005 8:53 am
It showing 02/11/05 09:51:54 when I ran your code at 9:51am
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Fri Nov 04, 2005 10:58 am
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 » Fri Nov 04, 2005 11:28 am
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
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Mon Nov 07, 2005 8:19 am
I'm running PHP 5.0.3. Does anyone has any other explanation for this date thing? Thanks...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Nov 07, 2005 8:31 am
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..
quadoc
Forum Contributor
Posts: 137 Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA
Post
by quadoc » Mon Nov 07, 2005 8:42 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Nov 07, 2005 8:43 am
it's a good idea to upgrade anyways.. so try it..