Jump to content

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.

Link to comment
Share on other sites

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

Thanks again,
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

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.