Solved

NEXT and PREV Date navigation

Posted on 2013-12-05
2
402 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 108

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now