Date Count Down

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
syno
Forum Newbie
Posts: 9
Joined: Wed Oct 15, 2003 11:22 am

Date Count Down

Post by syno »

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!
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

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;
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

errr sorry for that last post it was super wrong. this is really how u should do it.

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;
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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

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";
?>
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

ah well, this is really the last time i demonstrate...
I'll bet it's not.
syno
Forum Newbie
Posts: 9
Joined: Wed Oct 15, 2003 11:22 am

Post by syno »

well thanks guys you helped alot!! :)
Post Reply