jamjam Posted January 8, 2011 Share Posted January 8, 2011 Hi This is really driving me crazy, so please help. I have this code as shown below, it displays a list of dates for the next 7 days. Things i want the code achieve. 1. Display "Today and "Tomorrow" instead of the corresponding date. 2. Once a date is selected add "current" class, this way it is highlighted with a different color. 3. "Today" should be selected by default when the page is first loaded. The code below achieve this requirements <?php $today = date("d-m-Y", strtotime('today')); $tomorrow = date("d-m-Y", strtotime('tomorrow')); echo ' <li><a href="?date='.$today.'">'.(($_GET['date'] == $today) ? '<span class="current"' . '>Today</span>' : 'Today').'</a></li>'; echo ' <li><a href="?date='.$tomorrow.'">'.(($_GET['date'] == $tomorrow) ? '<span class="current"' . '>Tomorrow</span>' : 'Tomorrow').'</a></li>'; for ($time = strtotime('+2 days'), $i=0; $i < 5; $time = strtotime('+1 days', $time), $i++) {$date = date("d-m-Y", $time); echo ' <li><a href="?date='.$date.'">'.(($_GET['date'] == $date) ? '<span class="current">' : '') . date("D jS", $time) . ((isset($_GET['date']) && $_GET['date'] == $date) ? '</span>' : '') . "</a></li>";} ?> However recently i needed to change the formating of the date from d-m-Y to Y-m-d As result of this my third requirement the one about "Today" been selected by default no longer works. <?php $today = date("Y-m-d", strtotime('today')); $tomorrow = date("Y-m-d", strtotime('tomorrow')); echo ' <li><a href="?date='.$today.'">'.(($_GET['date'] == $today) ? '<span class="current"' . '>Today</span>' : 'Today').'</a></li>'; echo ' <li><a href="?date='.$tomorrow.'">'.(($_GET['date'] == $tomorrow) ? '<span class="current"' . '>Tomorrow</span>' : 'Tomorrow').'</a></li>'; for ($time = strtotime('+2 days'), $i=0; $i < 5; $time = strtotime('+1 days', $time), $i++) {$date = date("Y-m-d", $time); echo ' <li><a href="?date='.$date.'">'.(($_GET['date'] == $date) ? '<span class="current">' : '') . date("D jS", $time) . ((isset($_GET['date']) && $_GET['date'] == $date) ? '</span>' : '') . "</a></li>";} ?> Can someone please help with this. Thanks in advance Quote Link to comment Share on other sites More sharing options...
raj23 Posted January 25, 2011 Share Posted January 25, 2011 Hi, Why you are using so complicated code use simple code.The syntax for displaying today and tomorrow date $tomorrow = date ("Y-m-d", mktime (0,0,0,date("m"),(date("d")+1),date("Y"))); $actualdate = date("Y-m-d"); you can set today's as a default 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.