Solved

NEXT and PREV Date navigation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Pivot Question 8 43
mysql joining from the same table 6 29
datetime in sql 6 23
Checking if varaible is empty 6 25
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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.

932 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

14 Experts available now in Live!

Get 1:1 Help Now