Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-15-2005, 08:05 AM
  #1
RobertLees
Novice (Level 1)
 
Join Date: Sep 2005
Location: Sydney,Australia
Posts: 3
iTrader: (0)
RobertLees is an unknown quantity at this point
Date calculation

Hi

Is this possible in html?

I want to show the difference between a certain date, and the current date.

Thanks
Robert
RobertLees is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-15-2005, 08:32 AM
  #2
RysChwith
Super Guru
 
Join Date: Jun 2004
Posts: 4,117
iTrader: (0)
RysChwith will become famous soon enough
Not in HTML, but you can do it with JavaScript. I'll see if I can get someome to move this to the appropriate forum.

Rys
RysChwith is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-15-2005, 09:21 AM
  #3
BonRouge
Winemaster
 
BonRouge's Avatar
 
Join Date: Aug 2005
Location: Sendai, Japan
Posts: 3,070
iTrader: (0)
BonRouge has a spectacular aura aboutBonRouge has a spectacular aura about
If you have php available, you can use that.
If you just save this page with a php extension, you can see...
Here's the script in action.
If you need help implementing this, just say.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>The difference between one day and today.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form method="post" action=""><p><label>Enter the date (dd-mm-yy) : <input name="date1" /></label></p></form>
<?php 
function datediff($date1) {

// $date1 is subtracted from $date2.
// if $date2 is not specified, then current date is assumed.

//Splits date apart
list($date1_day, $date1_month,  $date1_year) = split('[/.-]', $date1);

if (!$date2) {
  $date2_year = date("Y"); //Gets Current Year
  $date2_month = date("m"); //Gets Current Month
  $date2_day = date("d"); //Gets Current Day
} else {
  list($date2_month, $date2_day, $date2_year) = split('[/.-]', $date2);
}

$date1 = mktime(0,0,0,$date1_month, $date1_day, $date1_year); //Gets Unix timestamp for $date1
$date2 = mktime(0,0,0,$date2_month, $date2_day, $date2_year); //Gets Unix timestamp for $date2

$difference = $date2-$date1; //Calcuates Difference
return floor($difference/60/60/24); //Calculates Days Old

}


if (isset($_POST['date1'])) {
$diff = datediff($_POST['date1']);
	if ($diff<0) {
	echo "<p>$date1 is ".substr($diff,1,10)." days from now.</p>";
	}
	else {
	echo "<p>$date1 was $diff days ago.</p>" ;
	}
}
?>
</body>
</html>
BonRouge is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 05:07 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.