Jump to content

Archived

This topic is now archived and is closed to further replies.

CanMan2004

php date help

Recommended Posts

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

2006-09-02

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

22/06/2006

I print it with the following code

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

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

Dave

Share this post


Link to post
Share on other sites
http://www.php.net/date

Everything you need to know about date formating ;)

Share this post


Link to post
Share on other sites
To foramt the date and echo in how many days it is:
[code=php:0]//$membershiprow['myexpiredate'] is something in the format of 2006-06-22
$old_format=$membershiprow['myexpiredate'];
$arr=explode("-",$old_format);
$new_format=$arr[2]."-".$arr[1]."-".$arr[0];
$time_expire=mktime(0,0,0,$arr[1],$arr[2],$arr[0]); //the timestamp of the date it expires
$sec_to_expire=$time_expire-time();
$days=floor($sec_to_expire/86400);
echo("Your membership expires on ".$new_format."<br>That's in ".$days." days!");[/code]
[hr]

Orio.

Share this post


Link to post
Share on other sites
It's much easier to use the strtotime() function:
[code]<?php
$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!";
?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.