Jump to content


Photo

mktime help *solved*


  • Please log in to reply
3 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 11 August 2006 - 12:53 AM

hey guys,

trying to build an array that cpntains all the days of the week starting by today.

I have this so far but for some reason it shows the date starting wednesday and not thursday ( I already tried doing echo date("l"); and it prints Thursday)

$days = array();
for ($i=1;$i<=7;$i++) {
	array_push($days,date("l", mktime(0,0,0,0,+$i,0)));	
}


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 August 2006 - 01:09 AM

I guess mktime( ...0,1,0) is something like January 2, 1970.

Use this instead:

<?php
list($y,$m,$d) = explode("-",date("Y-m-d"));
$days = array();
for ($i=0;$i<=6;$i++) {
	array_push($days,date("l", mktime(0,0,0,$m,$d+$i,$y)));
}
print_r($days);
?>

Legend has it that reading the manual never killed anyone.
My site

#3 DillyDong

DillyDong
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 August 2006 - 01:14 AM

Probably not the best way to fix it, but I just changed $i=2 and $i<=8 and it works.

#4 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 11 August 2006 - 01:26 AM

thanks AndyB that worked perfectly, for some reason I thought that I could have everything at 0 and just add a value for the days.

DillyDong, yeah I also tried that and it worked but I needed a permanent solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users