Page 1 of 1
subtracting hours from date
Posted: Thu Oct 25, 2007 10:18 pm
by GeXus
Code: Select all
$offset = "50";
$date = date("M-d-Y", mktime(date('H')-$offset, date('i'), date('s'), date('m'), date('d'), date('Y')));
This is what I have to subtract hours from the current day... the issue is that this only works with subtracting, and I want it to add as well... So ideally, I would have something like this..
Code: Select all
$offset = "+50";
$date = date("M-d-Y", mktime(date('H')$offset, date('i'), date('s'), date('m'), date('d'), date('Y')));
Of course, that does not work (unexpected variable).... Any ideas how to do this?
thanks!
Posted: Thu Oct 25, 2007 10:22 pm
by Zoxive
Why is the `+` in the Variable?
Code: Select all
$offset = 50;
$date = date("M-d-Y", mktime(date('H')+$offset, date('i'), date('s'), date('m'), date('d'), date('Y')));
Posted: Thu Oct 25, 2007 10:28 pm
by GeXus
I guess I can just create two functions one for add one for subject.... I was just thinking there might be a more efficient way that I could add and subtract with one instance
Posted: Thu Oct 25, 2007 10:40 pm
by Zoxive
Why not just have a condition statement, or do the addition/subtraction before hand?
Code: Select all
$Offset = date('H')+50;
$Time = offsetHrs($Offset);
//
$Offset = date('H')-50;
$Time = offsetHrs($Offset);
Posted: Fri Oct 26, 2007 7:59 pm
by rodrigoreis
Hi Everyone!
I´m working on a project, that has something to do with this subject.. I builded a flash clock, that loads a bunch os stuff depending on the server time, using a PHP file.
The script is working fine, I just need some help to adjust to my local time (+3 hours), since I know how to write anything in PHP...
If you could help me out here, i´d really appreciate!!!!
Here´s the PHP code:
Code: Select all
<?
print ("serverHour=".date("G:i:s A")."&weekDay=".date("l")."&date=".date("d.m.Y")."&");
?>
This returns 3 dinamic text field in Flash... I just need to add 3 hours..
Thanks!
Rodrigo
Posted: Fri Oct 26, 2007 11:18 pm
by mrkite
Zoxive wrote:Why is the `+` in the Variable?
Code: Select all
$offset = 50;
$date = date("M-d-Y", mktime(date('H')+$offset, date('i'), date('s'), date('m'), date('d'), date('Y')));
Just in case Zoxive didn't make it clear, offset can be negative and it'll subtract.
Code: Select all
$offset = -50;
$date = date("M-d-Y",mktime(date('H')+$offset, date('i'), date('s'), date('m'), date('d'), date('Y')));