Solved

NEXT and PREV Date navigation

Posted on 2013-12-05
2
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 110

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 110

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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