Jump to content

Date help - should be easy...


cmgmyr

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
Link to comment
https://forums.phpfreaks.com/topic/20534-date-help-should-be-easy/
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]
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

Archived

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

×
×
  • 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.