Hi, im new to php. im trying to write a program which counts down how many days are left for example
today = 01/24/05
bill is due on 01/27/05 - bill due in 3 days from now
and the next day (01/25/05) it would say
bill is due on 01/27/05 - bill due in 2 days from now
etc. which is the best way of doing this. thanks!
Date Count Down
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
use date() to get the current date and time and such, search php.net for that one (its easy as eating oranges). use the date() to define the month_today and such for the 1st part then u will havta predefine the $mont_bill_due and those some way else, maybe with a form saving to a db or txt or somtin. ask if u need more info
Code: Select all
$diffrence = gregoriantojd($month_today, $day_today, $year_today) - gregoriantojd($month_bill_due, $day_bill_due, $year_bill_due);
echo "this bill is due " . $diffrence;- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
errr sorry for that last post it was super wrong. this is really how u should do it.
this is all a lil sloppy but hopefully u look up date and mktime and actually learn how to do it then u will understand were im coming from, im just trying to give u a kick in the rite direction
Code: Select all
//get the hour, minute, second, month, day number of month, year with date
$today_hour = date();
$today_minute = date();
$today_second = date();
$today_month = date();
$today_monthday = date();
$today_year = date();
//check http://us3.php.net/manual/en/function.date.php for what to put in the () for each of the date functions
//do the same with when your bill is due
$bill_due_hour = "whatever";
//...do that until ur done the same amount as the today_ crap
$today = mktime($today_hour, $today_minute, $today_second, $today_month, $today_monthday, $today_year);
//naturnally u would do the same with the day of the bill being due, i wont do it in detail but u know
$due_date = mktime(//all that crap again);
//then u just subtract one from the other to get a numerical value of the time left till ur heat is turned off :D
$diffrence = $today - due_date;ah well, this is really the last time i demonstrate http://www.php.net/strtotime power :p
Code: Select all
<?php
$year = "2005";
$month = "01";
$day = "27";
$today = strtotime("now");
$dueday = strtotime("$year-$month-$day 12:12:12");
$diff = round(($dueday - $today) / ( 24 * 60 * 60));
echo "bill is due in $diff days";
?>