cmgmyr Posted September 12, 2006 Share Posted September 12, 2006 Hey sorry for this question but I couldn't find anything on it...I have reg_date in my database which is a datetime type. What I want to find out is the same date a year from now and if their account is active. I have it formatted right now as: $reg_date = date("M-d-Y", strtotime($reg_date));Thanks I'm sure this is easy and right under my nose, but I'm missing it right now.Thanks,-Chris Link to comment https://forums.phpfreaks.com/topic/20534-date-help-should-be-easy/ Share on other sites More sharing options...
HuggieBear Posted September 12, 2006 Share Posted September 12, 2006 Do you mean you want to add a year onto the reg_date column and see if it's in the past or not?Is that what you mean by 'active'?RegardsRich Link to comment https://forums.phpfreaks.com/topic/20534-date-help-should-be-easy/#findComment-90585 Share on other sites More sharing options...
obsidian Posted September 12, 2006 Share Posted September 12, 2006 so, you're wanting to add one year to the date, right? you can do it with strtotime:[code]<?php$reg_date = date('Y-m-d', strtotime("$reg_date + 1 year"));?>[/code]or, just do it when you query your database:[code]SELECT DATE_ADD(reg_date, INTERVAL 1 YEAR) AS reg_date FROM tableName;[/code] Link to comment https://forums.phpfreaks.com/topic/20534-date-help-should-be-easy/#findComment-90593 Share on other sites More sharing options...
cmgmyr Posted September 12, 2006 Author Share Posted September 12, 2006 Thanks obsidian I got it. Here is what I came up with:[code]$users = mysql_query("SELECT DATE_ADD(reg_date, INTERVAL 1 YEAR) AS ex_date, reg_date FROM users WHERE userid = $userid") or die('Query failed: ' . mysql_error()); $reg_date = mysql_result($users, 0, 'reg_date'); $ex_date = mysql_result($users, 0, 'ex_date'); $reg_date = date("M-d-Y", strtotime($reg_date)); $ex_date = date("M-d-Y", strtotime($ex_date)); $cdate = date("M-d-Y"); if ($cdate <= $ex_date){ $activity = "<span class=\"correct\">Active</span>"; }else{ $activity = "<span class=\"wrong\">Inactive</span><br /><br /><br />Please renew your membership."; }[/code]Thanks again,-Chris Link to comment https://forums.phpfreaks.com/topic/20534-date-help-should-be-easy/#findComment-90599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.