Jump to content

Archived

This topic is now archived and is closed to further replies.

cmgmyr

Date help - should be easy...

Recommended Posts

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

Share this post


Link to post
Share on other sites
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'?

Regards
Rich

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.