Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date - What's Wrong Here 1

Status
Not open for further replies.

jsnull

IS-IT--Management
Feb 19, 2002
99
US
I have the following simple script to get the name of day where I am looking for "Sunday".
Code:
<?php
$currentdate = "2009-01-01";

$junk = 1;

while ($junk = 1){
	
	$dayname = date('l', $currentdate);
	print "Date: $currentdate ~ $dayname<br>";
	if ($dayname == "Sunday"){
		print "   Date: $currentdate = $dayname<br>";
	}

$currentdate = strtotime ( '+1 day' , strtotime ($currentdate)) ;
$currentdate = date ('Y-m-d' , $currentdate );

if ($currentdate == "2010-01-01"){exit;}	
}

?>

The date increments fine, but the dayname stays Wednesday... here is the output.

Date: 2009-01-01 ~ Wednesday
Date: 2009-01-02 ~ Wednesday
Date: 2009-01-03 ~ Wednesday
Date: 2009-01-04 ~ Wednesday
Date: 2009-01-05 ~ Wednesday
Date: 2009-01-06 ~ Wednesday
Date: 2009-01-07 ~ Wednesday
Date: 2009-01-08 ~ Wednesday

Jim Null
info@ferncreek.com
 
Hi

Read the documentation of the [tt]date()[/tt] function. The second parameter has to be a timestamp, not a string.
Code:
[navy]$dayname[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]date[/color][teal]([/teal][green][i]'l'[/i][/green][teal],[/teal] [COLOR=darkgoldenrod]strtotime[/color][teal]([/teal][navy]$currentdate[/navy][teal]));[/teal]

Feherke.
 
Perfect ... thank you so very very much!

Jim Null

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top