almightyegg Posted November 8, 2006 Share Posted November 8, 2006 when a member signs up they have a date dd-mm-yyyy put into there row in a database...is there a way to find out how many days old a player is from its sign up date? Link to comment https://forums.phpfreaks.com/topic/26606-finding-out-days-old/ Share on other sites More sharing options...
Caesar Posted November 8, 2006 Share Posted November 8, 2006 I say this at least once a week...make life easier for yourself and do not store dates that are already formatted. Store them in the database as timestamps, then do your comparisons and date conversions after you've retrieved the data. Link to comment https://forums.phpfreaks.com/topic/26606-finding-out-days-old/#findComment-121708 Share on other sites More sharing options...
Orio Posted November 8, 2006 Share Posted November 8, 2006 Agrees with above.But if you are already "stuck" with formated dates, you can use explode() and mktime() to get the old time stamp and then compare it with the current timestamp.Orio. Link to comment https://forums.phpfreaks.com/topic/26606-finding-out-days-old/#findComment-121713 Share on other sites More sharing options...
Nicklas Posted November 8, 2006 Share Posted November 8, 2006 Use [url=http://www.php.net/strtotime]strtotime()[/url][code=php:0]<?php$sign_date = "01-11-2006"; // sign-up date in dd-mm-yyyy format$days = floor((time() - strtotime($sign_date)) / 86400); // 86400 = total seconds in 1 dayecho "You´ve been a member for $days days";?>[/code]Or even better, do it directly in your database query. Then you need your dates stored as timestamps... wich you should do when storing dates in your database.ex:[code=php:0]SELECT TO_DAYS(CURDATE()) - TO_DAYS(your_date_field) AS days FROM your_table[/code] Link to comment https://forums.phpfreaks.com/topic/26606-finding-out-days-old/#findComment-121800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.