Tomorrows Date?

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
simonjk
Forum Newbie
Posts: 1
Joined: Wed Oct 27, 2010 9:34 am

Tomorrows Date?

Post by simonjk »

Hi,

I am trying to show tomorrows date, using the date picked up from a file.

I can show the date and time the file was created as per below:

Code: Select all

$today = 'sbFCS12.csv'; 
if (file_exists($today)) { 
echo "File updated at: " . date ("D d	 F Y H:i", filemtime($today));} 


But cannot get tomorrows date to show using: 

$tomorrow = 'sbFCS12.csv'; 
if (file_exists($tomorrow)) { 
echo "File updated at: " . date ("d")+1, filemtime($tomorrow));} 
Can anyone help?

Thanks,
Simon
Last edited by Eran on Wed Oct 27, 2010 12:15 pm, edited 1 time in total.
Reason: Added [syntax=php][/syntax] tags. Please use those in the future
phppro62
Forum Newbie
Posts: 16
Joined: Wed Oct 27, 2010 2:45 am

Re: Tomorrows Date?

Post by phppro62 »

hi mate
I'll give you the tip and you will carry on

$today= date("d") ;
$tomorrow=$today+1 ;
echo $tomorrow ;
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Tomorrows Date?

Post by VladSun »

Code: Select all

strtotime('tomorrow')
There are 10 types of people in this world, those who understand binary and those who don't
phppro62
Forum Newbie
Posts: 16
Joined: Wed Oct 27, 2010 2:45 am

Re: Tomorrows Date?

Post by phppro62 »

YES you can use the function strtotime() but it will give you along number
To use it practically you should put it in a function
you cn try this

Code: Select all

<?php
 
function d_of_tomorrow($date)
{
    if(preg_match('/([012]?[0-9]?:[0-5]{1}\d\s*[aA|pP]?[mM]?)(\s+)(.+)/', $date, $matches))
    {
        return strtotime($matches[3] . $matches[2] . $matches[1]);
    }
    return strtotime($date);
}
echo date('Y-m-d ', d_of_tomorrow('tomorrow ')); // 2010-10-28 

?>

User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Tomorrows Date?

Post by Eran »

In your first use (today) you put the timestamp inside the date() function to format it. You should be doing the same for 'tommorow', only you need to increment the timestamp in seconds.

Code: Select all

date ("D d F Y H:i", filemtime($tomorrow) + 3600 * 24);
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Tomorrows Date?

Post by klevis miho »

First use this function to set the timezone(because the server may have a different timezone than yours):
bool date_default_timezone_set ( string $timezone_identifier )

Then:
$tomorrow = date ("D d F Y H:i", time() + 84600);
Post Reply