trilbyfish Posted April 22, 2008 Share Posted April 22, 2008 How would i set uo the php date function so that at 6pm it prints the following day? So it would say 'table for 'today's date'' upto 5:59pm and then at 6pm it was say 'table for 'tomorrow's date''? I hope i have explained this so someone can understand it, its hard to explain. Thanks in advance Quote Link to comment Share on other sites More sharing options...
tibberous Posted April 22, 2008 Share Posted April 22, 2008 echo (if(date('G') < 14) ? date('l') : date('l', time()+60*60*24)); That work? Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 22, 2008 Author Share Posted April 22, 2008 Ahha i didnt think of that! No that didnt work, but maybe if i did something like if hour<6 echo todays date else echo tomorrows date. How would i do that? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 22, 2008 Share Posted April 22, 2008 Tibberous was pretty much there - just you dont need the if keyword with the ternary operator, and that we should be checking if the hour is less than 18, not 14: echo ((date('G') < 18) ? date('l') : date('l', time()+60*60*24)); Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 24, 2008 Author Share Posted April 24, 2008 Thanks for that, it was really helpful. One more thing, how could i improve on that so that also tomorrows date is displayed after 6pm, and not just the day? Thanks in advance Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 24, 2008 Share Posted April 24, 2008 Take a look at the date() function. It will show you how to achieve whatever output you're looking for. Basically, you need to change the 'l' for whatever you want. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 24, 2008 Share Posted April 24, 2008 Just to be picky... There's now two sets of brackets so you could use this: echo (date('G')<18) ? date('l') : date('l',time()+60*60*24); Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 25, 2008 Author Share Posted April 25, 2008 How do i do the (date('G')<18) ? date('l') : date('l',time()+60*60*24) thing so that if the next day is a saturday or sunday, it shows monday? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 26, 2008 Share Posted April 26, 2008 Well im guessing you want this to show monday at any time over the weekend too? Try: <?php $x=0; $day = date('N'); $hour = date('G'); if($day == 5 && $hour >= 18){//after 6 on friday $x = 3; }elseif($day == 6){//saturday $x = 2; }elseif($day == 7){//sunday $x=1; }elseif($hour >= 18){//any other day of the week $x=1; } echo date('l dS F',time()+60*60*24*$x); ?> Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted April 28, 2008 Author Share Posted April 28, 2008 Thank you very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.