Jump to content


Date help - should be easy...

  • Please log in to reply
3 replies to this topic

#1 cmgmyr

  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 12 September 2006 - 06:16 PM

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.


#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 12 September 2006 - 06:22 PM

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'?

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 12 September 2006 - 06:26 PM

so, you're wanting to add one year to the date, right? you can do it with strtotime:
$reg_date = date('Y-m-d', strtotime("$reg_date + 1 year"));

or, just do it when you query your database:
SELECT DATE_ADD(reg_date, INTERVAL 1 YEAR) AS reg_date FROM tableName;

You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 cmgmyr

  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 12 September 2006 - 06:41 PM

Thanks obsidian I got it. Here is what I came up with:

$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>";
			$activity = "<span class=\"wrong\">Inactive</span><br /><br /><br />Please renew your membership.";

Thanks again,

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users