Solved

NEXT and PREV Date navigation

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 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