Total members 11365 |It is currently Thu Oct 23, 2014 3:57 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R

All times are UTC [ DST ]



  find the difference between dates in asp.net
Fri Apr 08, 2011 9:36 pm 

Following code check the difference between dates and return the number of years as difference between two dates
Code:

Function testYear
(ByVal inputDate, ByVal testDate, ByVal strDifference)
   
    Here we test using years 
(yyyy) , difference in years .
    strDifference = DateDiff("yyyy", testDate, inputDate)
    If strDifference < 18 Then
        Response
.Write("Sorry you must be older than 18 years")
    Else
        Response
.Write("Welcome ,you can enter this site.")
    End If
End Function
 


Also you can do it for number of days .
Code:

Function diffDays
(ByVal inputDate, ByVal testDate, ByVal strDifference)
   
    
'Here we test using years (yyyy)
    testDate = "11/12/2001"
    '
here we show difference in days.
    strDifference = DateDiff("d", testDate, inputDate)
     
    
     print the difference in page
.
    Response.Write(strDifference & " to date " & testDate)
    
End Function
 

You can use "h" for hour ,"m" for month ,"d" for day ,"yyyy" for year ,"s" for seconds ,"q" quarter ,"n" for minutes.

You can add a units of time to a specific date like the following
Code:
<% 
    Dim dateToday
, dateAfterAdd
    dateToday 
= Date.Now
    Response
.Write("current date is " & dateToday & "<br>")
     add 6 years to a date .
    dateAfterAdd = DateAdd("yyyy", 6, dateToday)
    Response.Write("After adding 6 Years<b> " & dateAfterAdd & "</b><br>")
%>
 


You can also get a part of date :
Code:

Dim d_mydate
d_mydate
=Now
 Get the month part of my date 
.
Response.Write DatePart("m",d_mydate)
 


You can also format the date :
Code:

currDate
=Now 
Response
.Write "Date Formatted : "FormatDateTime(currDate,0)
 

the FormatDateTime function takes two parameters ( date ,index for type of format)
0 -> vbGeneralDate 3/14/2010 4:48:49 AM Date and Time
1-> vbLongDate Friday, April 14, 2010 Date in Long format
2->vbShortDate 2/12/2010 Date in m/d/yyyy
3->vbLongTime 1:13:11 AM Long Time
4->vbShortTime 10:00 Short Date

_________________
Please recommend / share my post if you found it helpful.


Author:
Mastermind
User avatar Posts: 2694
Have thanks: 73 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : find the difference between dates in asp.net
 DYNAMIC DATES IN MYSQL     -  
 Formatting dates in mysql     -  
 Comparing Dates in Java     -  
 Find entity by id     -  
 find a string     -  
 Find MAC Address     -  
 how to find size without using sizeof     -  
 cannot find symbol constructor     -  
 Not to find nativeEncoder class jar     -  
 Find occurrences of each character in a string     -  

All times are UTC [ DST ]



Topic Tags

ASP Time






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team