date functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

date functions

Post by SidewinderX »

ok, im about to create a script that send's bills to my customers atuomatically, but im having a little issue with the dates. My idea is to have a database that has a "payment_due" column and a "next_payment" column. Then have a cron run the script every day. And the script will obviousally check to see that if todays date is the same as the date in the payment_due column and if it is it will send the email, and create a new payment_due value and a next_payment value in the database that is dependent on the payment cycle. (every month, 3 months ect...)

My issue is creating the next_payment date.

The first idea that came to mind was

Code: Select all

$date = date('d m');
which takes care of the current date, but what about the next payment? So then i thought of doing something like

Code: Select all

$nextMonth = time() + (4 * 7 * 24 * 60 * 60);
$date = date('d m', $nextMonth);
but not every month has 4 weeks of 7 days, so that would cause an error down the line. My final idea was to do this

Code: Select all

$nextMonth = mktime(0, 0, 0, date("d"),  date("m")+1));
which i assume does work but i find that a little imtimidation as i have no idea what any of those numbers (0, 0, 0) mean and ii have no idea how 1157169600 means September 02, and php.net dosnt do a really good job explaining it, anyone care to offer some input?
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Post by tmaiden »

Why not use DateAdd?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The number you are seeing is called a unix timestamp. It is the number of seconds from January 1st 1970 at midnight GMT, if memory serves. This specific time is called the epoch or Unix epoch.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

This should get you started... (If you read the manual pages, you'll find also answers to your other questions...

Code: Select all

<?php
echo date('Y-m-d', strtotime('+1 months'));
?>

But i prefer to leave all the processing to MySQL instead...

Code: Select all

SELECT DATE_ADD(NOW(), INTERVAL 1 MONTH);
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

ah.. thanks for all your help, ive got it now :D
Post Reply