CanMan2004 Posted July 5, 2006 Share Posted July 5, 2006 Hi allI 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 format2006-09-02Currently 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 as22/06/2006I 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 alwaysThanks in advanceDave Link to comment https://forums.phpfreaks.com/topic/13725-php-date-help/ Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 http://www.php.net/dateEverything you need to know about date formating ;) Link to comment https://forums.phpfreaks.com/topic/13725-php-date-help/#findComment-53264 Share on other sites More sharing options...
Orio Posted July 5, 2006 Share Posted July 5, 2006 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. Link to comment https://forums.phpfreaks.com/topic/13725-php-date-help/#findComment-53286 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 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 Link to comment https://forums.phpfreaks.com/topic/13725-php-date-help/#findComment-53324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.