Page 1 of 1

Get last day?

Posted: Mon May 31, 2010 8:19 pm
by angelicodin
Hey ya guys, I was doing some searching around on the PHP manual and goggle and what not, and I couldn't find the answer.

What I'm trying to do is get the previous date. I saw a bunch of a things on getting the first and last day of the current month and what not, but nothing about previous day.

What I was thinking I could do is take the current day, -1 to it and that would give me the right number and if it =0 then do an if() and -1 to month then get last day of the previous month.

Thoughts?

Re: Get last day?

Posted: Mon May 31, 2010 8:36 pm
by requinix

Code: Select all

strtotime("yesterday")

Re: Get last day?

Posted: Mon May 31, 2010 8:44 pm
by angelicodin
you sir are a godsend ;p

Re: Get last day?

Posted: Mon May 31, 2010 8:46 pm
by mikosiko
I will use something like this (adjust to your needs):

Code: Select all

<?php

$Today = time();
$Tomorrow = $Today + 86400;
$Yesterday = $Today - 86400;
echo 'Today = ' . date('Y-m-d',$Today) . ' Tomorrow = '. date('Y-m-d',$Tomorrow) . ' Yesterday = '. date('Y-m-d',$Yesterday) . "<br /";

$nextWeek = $Today + (7 * 24 * 60 * 60);  // 7 days; 24 hours; 60 mins; 60secs ... or 7 * 86400

echo 'Next Week: '. date('Y-m-d', $nextWeek) ."<br />";
// or using strtotime():
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."<br />";
?>

Re: Get last day?

Posted: Mon May 31, 2010 9:00 pm
by requinix
mikosiko wrote:I will use something like this (adjust to your needs):
Except twice a year it won't behave correctly.

Re: Get last day?

Posted: Mon May 31, 2010 9:04 pm
by mikosiko
You are right tasairis.... I was trying to transmit him the concept of how to work with unix-like timestamps ... Y let the DST out of the picture

Re: Get last day?

Posted: Tue Jun 01, 2010 1:41 am
by angelicodin
Thank you all of you, seems I have more to learn time formatting and manipulation. Brilliant.