Jump to content


Photo

[solved] add time() to date() with $row ?


  • Please log in to reply
2 replies to this topic

#1 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 15 September 2006 - 03:55 PM

Hi,

I dunno if that title makes any sense... basicly I have this:
$month = date("m", $row['a_dfrom']);

but I want to take away 1 from it, doing -1 like..

$month = date("m", $row['a_dfrom'])-1;

this seems to transfer any thing like 01 - 09 to 1 - 9 so when php checks to see if 08 is 08 it comes up 8 is 08.

is there any way of fixing this?

thanks in advance.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 15 September 2006 - 06:12 PM

When you subtract one, PHP changed the string to an integer, so it doesn't have a leading zero.

Try this:
<?php
$month = sprintf("%02d",date("m", $row['a_dfrom'])-1);
?>

Ken

#3 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 16 September 2006 - 11:58 AM

thanks, that solves my problem :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users