Get last day?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Get last day?

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get last day?

Post by requinix »

Code: Select all

strtotime("yesterday")
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Re: Get last day?

Post by angelicodin »

you sir are a godsend ;p
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Get last day?

Post 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 />";
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get last day?

Post by requinix »

mikosiko wrote:I will use something like this (adjust to your needs):
Except twice a year it won't behave correctly.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Get last day?

Post 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
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Re: Get last day?

Post by angelicodin »

Thank you all of you, seems I have more to learn time formatting and manipulation. Brilliant.
Post Reply