|
Hi All,
I am very much new to ASP programming. I am developing a Leave Management portal. I need to calculate the difference between two dates (including the From and To date).
For Example consider the below scenario:
A person applies leave from 01/03/2010 to 05/03/2010 and clicks on submit button.
In addition to checking all the mandatory fields, I have to check whether the number of days applied is greater than 3 (including from date and To date). If yes, I have to display an error message.
Please Help me out to solve this.
|
|
|
Hi,
To calculate the difference in date in days, you can use the following method:
DateTime leave;
DateTime back;
leave = Convert.ToDateTime(txtdate1.Text);
back = Convert.ToDateTime(txtdate2.Text);
TimeSpan gone = leave - back;
int daysgone = gone.Days
if(daysgone > 3)
{
//insert conditional code
}
As for the txtdate1.text, thats just however the user is passing their date value into your program. Hope this helps.
<Added>
Edit - O wow, sorry, didnt' notice you wanted this is javascript. Sorry.
<Added>
javascript:
var date1 = (input date)
var date2 = (input date)
var one_day = 1000*60*60*24;
Document.write(Math.ceil(date2.getTime() - date1.getTime())/(one_day))
source: http://www.javascriptkit.com/javatutors/datedifference.shtml
|
|
|
Tutorials PHP Tutorials
Calculating Difference Between Two Dates Using PHP
By Amrit Hallan
2005-10-18
Calculating difference between two dates using PHP
AdsSpy: 15 sites philadelphia mortgage loans by this AdSense ID Suppose you want to know the age of a person given her birth date. Let’s say her birth date is "09-23-1969". Although in this case you might las vegas investment property say that we don’t need a program to compute the age, but assuming there are 1000s of records in your database and for every person you have to print a report like:Sheila is 29 years oldFatima is 33 years oldPeter is 17 years old
… and so onIn the database we don’t generally store what the person’s age is — we store what the person’s date of birth is. This is because given the date of birth, we can always deduct it from today’s washington mortgage loans date and calculate the number of years that person has lived so far. Calculating date difference also comes handy if you are running a subscription-based website. You need to know for how many days a person has been using your website and when the subscription is due. So in this tip we learn to write a function that columbus mortgage loans returns us the number of days elapsed between two dates. First the function (I’ll discuss it later on)
function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}
Now let us see how we use this function:
$date1="07/11/2003";
$date2="09/04/2004";
print "If we minus " . $date1 . " from " . $date2 . " we get " . dateDiff("/index.html", $date2, $date1) . ".";
which generates If we minus 07/11/2003 from 09/04/2004 we get 421.
The dateDiff() functions uses two PHP functions viz., explode() and gregoriantojd(). The explode() function is used mostly to convert strings san francisco real estate into arrays. It takes two arguments: the separator and the string. So if
$string="Trees, plants, bushes";
$stringparts=explode(", ", $string);
then $stringparts[0] holds "Trees", $stringparts[1] holds "plants" and $stringparts[2] holds "bushes". The separator is ", ". Similarly, in the above example, $date_parts1[0] holds the month part, $date_parts1[1] holds the day part and $date_parts1[2] holds the year part and these are the arguments that the function gregoriantojd() needs. The syntax of the gregoriantojd() function is
gregoriantojd($month, $day, $year)
But why do we need this function? Without going into the gory details, it changes the date into a big number from which another number (obtained from another date) can be deducted. Having said that, let us now see a few applications for this function: first the age thing. The following snippet of code gives us the age of a person according to the current date.
|
|
|
|
|
Hi all,
I am Hank Freid and I like your
blog very much.
|
|
|
Codes can be used for brevity. When telegraph messages were the state of the art in testking ccna dumps rapid long distance communication, elaborate systems of commercial codes that encoded complete phrases into single words (commonly five-letter groups) were developed, so that telegraphers became conversant with such "words" as BYOXO ("Are you trying to weasel out of our deal?"), LIOUY ("Why do you not answer my question?"), BMULD ("You're a skunk!"), or AYYLU ("Not clearly coded, repeat more clearly."). Code words were chosen testking ccsa for various reasons: length, pronounceability, etc. Meanings were chosen to fit perceived needs: commercial negotiations, military terms for military codes, diplomatic terms for diplomatic codes, any and all of the preceding for espionage codes. Codebooks and codebook publishers proliferated, including one ccnp run as a front for the American Black Chamber run by Herbert Yardley between the First and Second World Wars. The purpose of most of these codes was to save on cable costs. The use of data coding for data compression predates the computer era; an early example is the telegraph Morse code where more-frequently used characters have shorter representations. Techniques such as Huffman coding are now used by computer-based algorithms to ccvp compress large data files into a more compact form for storage or transmission
|
|
|
|
|
|
|
at the moment I'm working 70-445
on writing a code for a interactive project. This project is made out of a 3dmodel, that I made in 3dsmax. I want to animate this model, and make it respond to an actual person 70-443
by motion detectors and a camera that works together with a javascript code.I'm trying to make this animated model walk to different coordinates. When doing so I have two different choices, either my object 'slides' to a location, or the object do 70-444
es a 'walkcycle' which remains in place. (So the background moves.) What I want, ideally, is a sliding walkcycle. This has to have a place where it has to stop, so it doesn't move out of the picture. (I hope this still makes some sense!)70-442
|
|
|
Very interesting discussion. I am glad to have found this and I am now kotting notes. Thanks.
-------------------
KarenG of chicago website design company
|
|
|
I think the answer is very clear and helpful! Thanks for your wonderful knowledge with us!
--------------------------------- http://www.logo-maker.net
<Added>
I think the answer is very clear and helpful! Thanks for your wonderful knowledge with us!
--------------------------------- http://www.logo-maker.net
|
|
|
|
|
|
|
|