Solved

NEXT and PREV Date navigation

Posted on 2013-12-05
2
407 Views
Last Modified: 2013-12-10
I am trying to create a Previous week and Next Week button:  However, I'm not sure what I am doing wrong right now;
$timestamp      = strtotime(date('Y-m-01', strtotime($date)));
    $caption     	= date("F Y", $timestamp);
   	$week_number 	= date("W");
	$year 			= date("Y");
	
	$date = !empty($_GET['d']) ? $_GET['d'] : 'Today';
	$prev = date('Y-m-01', strtotime("$date - 1 week"));
	$next = date('Y-m-01', strtotime("$date + 1 week"));
	$prev_link = '<a href="' . $_SERVER['PHP_SELF'] . "?d=$prev" . '">Prev</a>' . PHP_EOL;
	$next_link = '<a href="' . $_SERVER['PHP_SELF'] . "?d=$next" . '">Next</a>' . PHP_EOL;

Open in new window

0
Comment
Question by:rgranlund
  • 2
2 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39699834
It looks like you may be confusing the pattern for months with the pattern for weeks.  Please read this article and while you do that I will see if I can give you a design pattern that works.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39699842
This seems to work: http://www.laprbass.com/RAY_temp_rgranlund.php

<?php // RAY_temp_rgranlund.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28311728.html

$ts = !empty($_GET['d']) ? strtotime($_GET['d']) : strtotime('Today');
if (!$ts) $ts = strtotime('Today');
$prev = date('Y-m-d', $ts - 60*60*24*7);
$next = date('Y-m-d', $ts + 60*60*24*7);

$prev_link = '<a href="' . $_SERVER['PHP_SELF'] . "?d=$prev" . '">Prev</a>' . PHP_EOL;
$next_link = '<a href="' . $_SERVER['PHP_SELF'] . "?d=$next" . '">Next</a>' . PHP_EOL;

echo $prev_link . ' ' . $next_link;

Open in new window

0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question