Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 24th Mar 2009, 02:29 PM   #1
Active Warrior
War Room Member
 
Join Date: 2009
Posts: 59
Thanks: 5
Thanked 0 Times in 0 Posts
Default
Please help! PHP create date
Share on: 
fb share twitter share gplus share more share

Hi everybody,

does anyone know a php script, which does not create the current date but the date of some days ago? If this script would randomly go back some days, like one guy sees the date 3 days ago another 6 days ago and so on, that would be perfect.

Thanks in advance.
angelus_1984 is offline  
Unread 24th Mar 2009, 03:23 PM   #2
Gary
 
GB2008's Avatar
 
Join Date: 2009
Location: Dallas, TX
Posts: 135
Thanks: 13
Thanked 8 Times in 8 Posts
Blog Entries: 1
Default
Re: Please help! PHP create date
Share on: 
fb share twitter share gplus share more share

Not sure where you're going with this, but...

<?php
$countback = rand(1,30);
echo "Counting back ".$countback." days<br>";
$thePHPDate = getdate(time()); // Covert to Array
$thePHPDate['mday'] = $thePHPDate['mday']-$countback; // subtract our random number
$timeStamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']); // Convert back to timestamp
echo date("r", $timeStamp);
?>


Just change the parameters in rand() to change the range of days you go back by. This is up & running here

GB2008 is offline  
Unread 24th Mar 2009, 03:24 PM   #3
Gary
 
GB2008's Avatar
 
Join Date: 2009
Location: Dallas, TX
Posts: 135
Thanks: 13
Thanked 8 Times in 8 Posts
Blog Entries: 1
Default
Re: Please help! PHP create date
Share on: 
fb share twitter share gplus share more share

Not sure where you're going with this, but...

<?php
$countback = rand(1,30);
echo "Counting back ".$countback." days<br>";
$thePHPDate = getdate(time()); // Covert to Array
$thePHPDate['mday'] = $thePHPDate['mday']-$countback; // subtract our random number
$timeStamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']); // Convert back to timestamp
echo date("r", $timeStamp);
?>


Just change the parameters in rand() to change the range of days you go back by. This is up & running here

GB2008 is offline  
The Following User Says Thank You to GB2008 For This Useful Post:
Unread 25th Mar 2009, 05:34 AM   #4
Active Warrior
War Room Member
 
Join Date: 2009
Posts: 59
Thanks: 5
Thanked 0 Times in 0 Posts
Default
Re: Please help! PHP create date
Share on: 
fb share twitter share gplus share more share

Thanks so much. That was almost exactly where I was going.

Just one thing... After the time it always says +0100... I am from Germany so perhaps I don't get it. But does it refer to the different time zones in the US? If so could I change the script to just say EST or s.th. like that after the time?

Thanks again.
angelus_1984 is offline  
Unread 25th Mar 2009, 05:54 AM   #5
Gary
 
GB2008's Avatar
 
Join Date: 2009
Location: Dallas, TX
Posts: 135
Thanks: 13
Thanked 8 Times in 8 Posts
Blog Entries: 1
Default
Re: Please help! PHP create date
Share on: 
fb share twitter share gplus share more share

All you need to do is change the format parameter in the date() function. "r" defines the standard UTC timestamp - so that +0100 means the time displayed is 1 hour ahead of UTC - which sounds right for a German server to me.

For all the possible formatting options - take a look at php.net and search for date() - there's some great information and worked examples on that website.

GB2008 is offline  
Closed Thread


Bookmarks

Tags
create, date, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 06:31 PM.