cjbeck71081 Posted September 17, 2008 Share Posted September 17, 2008 Ok, so i am having a bear of a time trying calculate dates. Any help would be apprecaited. So I am timestamping dates in SQL entries using the "INSERT INTO table (`mydate`) VALUES (CURDATE())" This is populating the database with a date similar to this: 2008-09-17 This allows me to do a query of the database by saying "SELECT * FROM table WHERE mydate < CURDATE() - INTERVAL 30 DAY"; This part works great.. then I can send notifications to people who are past 30 days, and all are happy. But now I am trying to display date information in a table for the customer to see. For example... if Bob signed up for an account he'll have a field for su_date(signup date) and it would get '2008-09-17'. If I then wanted to make a table for a client that said... Bob signed up on 09-17-2008 and then calculate his renewel date of 30 days later... by saying Bob needs to renew by 10-17-2008. How would i do that? I have tried taking the value of mydate from the table and adding 30 to it... that just adds 30 years to the date. I'm sure i can reorder the numbers and add form there, but what a mess. Any ideas or methods would be awesome. Thanks Guys CJ Link to comment https://forums.phpfreaks.com/topic/124682-php-date-format-from-sql-and-calculate/ Share on other sites More sharing options...
GingerRobot Posted September 17, 2008 Share Posted September 17, 2008 Umm, i'd use a combination of date() and strtotime() Something like: $date = '2008-09-17'; echo date('d-m-Y',strtotime($date)+60*60*24*30); Link to comment https://forums.phpfreaks.com/topic/124682-php-date-format-from-sql-and-calculate/#findComment-643983 Share on other sites More sharing options...
Barand Posted September 17, 2008 Share Posted September 17, 2008 or $date = '2008-09-17'; echo date('m-d-Y',strtotime("+30 days $date")); Link to comment https://forums.phpfreaks.com/topic/124682-php-date-format-from-sql-and-calculate/#findComment-644020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.