Jump to content


php date help

  • Please log in to reply
3 replies to this topic

#1 CanMan2004

  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 05 July 2006 - 10:55 AM

Hi all

I have a website where users can sign up and they are given 30 days access to the site, I store the date the membership should expire in my sql database in the following format


Currently I show in there user details the date their membership expires as

"Your membership expires on 2006-06-22"

A have a couple of questions. Firstly, how can I format the date to display it as


I print it with the following code

<? print $membershiprow['myexpiredate']; ?>

And secondly, is it possible to count down the days until that date, so if the membership expired tomorrow then it would print the phase

"Your membership expires in 1 day"

Any help would be appricated as always

Thanks in advance


#2 mrwhale

  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 11:01 AM


Everything you need to know about date formating ;)

#3 Orio

  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 05 July 2006 - 12:22 PM

To foramt the date and echo in how many days it is:
//$membershiprow['myexpiredate'] is something in the format of 2006-06-22
$time_expire=mktime(0,0,0,$arr[1],$arr[2],$arr[0]); //the timestamp of the date it expires
echo("Your membership expires on ".$new_format."<br>That's in ".$days." days!");

Think you're smarty?

(Gone until 20 to November)

#4 kenrbnsn

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

Posted 05 July 2006 - 01:49 PM

It's much easier to use the strtotime() function:
$days = floor((time() - strtotime($membershiprow['myexpiredate']))/86400);
echo 'Your membership expires on ' . date('d/m/Y',strtotime($membershiprow['myexpiredate'])) . "<br>That's in $days days!";


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users