Jump to content


Photo

mySQL date mktime problems!!!


  • Please log in to reply
4 replies to this topic

#1 emilyfrazier

emilyfrazier
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 16 October 2006 - 01:55 PM

Hi all,

I am still fairly new to PHP and mySQL. I have read all the tutorials on dates, yet I'm still not seeing the light today.

So I have a field in my database called 'date_joined' that holds a timestamp when a users signs up for membership. I need to make a report that tells me all the memberships that will expire within the next 30 days (memberships are for 1 year).

Is there a way to take my field and use mktime to add 1 year to it? I assume it's possible through a function that breaks up the date and then subs them in to a mktime string, but I was wondering if there is an easier way around it?

I would really appreciate any help in advance.

Thanks so much,
eef

#2 neoform

neoform
  • Members
  • PipPipPip
  • Advanced Member
  • 241 posts
  • LocationMontreal

Posted 16 October 2006 - 02:00 PM

is it a `datetime` timestamp ?

date('Y-m-d H:i:s', time() + (365 * 24 *60 * 60));

Newsique.com Social News Network

#3 emilyfrazier

emilyfrazier
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 16 October 2006 - 02:12 PM

Thanks so much for the help...it doesn't work quite right. It is taking today's date if I use this code. I tried:

$yr = date('Y-m-d H:i:s', time($data['date_joined']) + (365 * 24 *60 * 60));


And it gives me today's date a year from now...I need it to take a year from now from the 'date_joined' field...thanks again

eef

#4 emilyfrazier

emilyfrazier
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 16 October 2006 - 02:14 PM

I got it working using this:
$datemysqlyr = date ( "Y m d H:i:s" , strtotime ( $data [ 'date_joined' ])  
+ (365 * 24 *60 * 60)); 

Thanks very much for your help!!

eef

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 October 2006 - 03:47 PM

You can also use:
<?php $datemysqlyr = date('Y m d H:i:s',strottime($data [ 'date_joined' ] . ' + 1 year')); ?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users