Click to See Complete Forum and Search --> : calculating dates


cashton2k
11-18-2006, 05:50 AM
im trying to calcualte a month ahead from a variable stored in an sql database and then work out if today is before or after the date calculated, what i have now isnt working cos i dont think im formatting the date right.
any ideas?


$today = date("m.d.y");
$nextdate = date("m.d.y");
$previousdate = $row['Previousdate'];

$nextdate = date("m", $previousdate)+1;


if ($nextdate > $today){



cheers for any help

bokeh
11-18-2006, 06:00 AM
If i'm understanding you correctly,you should be using the database to do this for you, not PHP. Something like the following:

SELECT `something` FROM `tablename` WHERE DATE_ADD(CURDATE(),INTERVAL 1 MONTH) >= `date_col` AND NOW() <= `date_col`;

cashton2k
11-18-2006, 07:30 AM
i want todo it so that when todays date is greater than a month stored in the database i can do a calculation e.g interest. can this be done the sql way?

im not very good a describin programming stuff lol

cheers for the help

bokeh
11-18-2006, 09:41 AM
Probably but you will need to give more details of your table structure for anyone to give you a relevant answer.

cashton2k
11-18-2006, 09:59 AM
basically the table has a record for each user, each user has an amount and a Previousdate field. the previous date field stores a date as a varchar in the date("m.d.y") format. at the top of the page the username is detected from a session.

bokeh
11-18-2006, 10:11 AM
Why did you use a varchar field for a date? I pretty sure you can still do it but not sure how. There was a thread about this recently.

cashton2k
11-18-2006, 10:22 AM
i tried using datetime but i kept getting a Data truncated error

cashton2k
11-19-2006, 04:49 AM
stopped the above happening now