Incrementing or Decrementing a variable with unix timecode

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
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Incrementing or Decrementing a variable with unix timecode

Post 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,
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

we actually need to increment a day or take away a day

Post by irishmike2004 »

the way we are getting our timestamp is by:

Code: Select all

$variable = time();
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.
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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
Post Reply