Total members 11895 |It is currently Mon Dec 30, 2024 5:12 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


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

  Related Posts  to : find the difference between dates in asp.net
 Get Difference in days between two dates as a number     -  
 Formatting dates in mysql     -  
 Comparing Dates in Java     -  
 DYNAMIC DATES IN MYSQL     -  
 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     -  



Topic Tags

ASP Time
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com