Page 1 of 1
Incrementing or Decrementing a variable with unix timecode
Posted: Wed Jan 12, 2005 2:56 pm
by irishmike2004
I have a rather interesting problem... I am still really new to PHP and I have some C++ background.
I am working on a project where we take the day as a unix time code and either decrement or increment it depending on the outcome of a test
I foolishly thought that it would work to just use:
$variableName++ ( or $variableName--) but alas it just seems to ignore the operator.
Can anybody help on this?
Thanks,
Posted: Wed Jan 12, 2005 3:06 pm
by rehfeld
if the contents of your variable is either an integer, or a numeric string, that should work.
you sure you dont have the increment inside a conditional statement that never gets evaluated?
if its not a regular timestamp, youll need to convert it back into a timestamp before you can increment it.
Posted: Wed Jan 12, 2005 3:07 pm
by feyd
what function did you use to get the unix timestamp? If it's from outside php, can you post an example of one?
If it's a ULONG, then ++ and -- will work, but will only add or subtract 1 second of time....
If it looks like 200501121506 then it's not a time stamp, but a printed evaluation of one. If it's that, I can post a regular expression to extract the time information and convert it back to timecode.
we actually need to increment a day or take away a day
Posted: Wed Jan 12, 2005 3:11 pm
by irishmike2004
the way we are getting our timestamp is by:
I need to for example if today is 12 January 2005 and we convert that into a timecode via strtotime() and then we want to increase that to 13 of January
I think I figured it out... thanks.
Posted: Wed Jan 12, 2005 7:34 pm
by printf
Hi
I don't know how you did it, but here is the shortest way to do what you wanted!
Code: Select all
<?
$date = '12 January 2005';
echo date ( 'd F Y', strtotime ( $date . "+ 1 day" ) );
?>
You can change the output format in the date() function to how you want it displayed!
printf