Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 7:11 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: find the difference between dates in asp.net
PostPosted: Fri Apr 08, 2011 9:36 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2272
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 NEED CODE OF find any num all divisor using recursion?
 Not to find nativeEncoder class jar
 Hows does Windows find Java?
 difference between upcasting and downcasting
 Difference between PHP echo() and PHP print()?
 Calendar dates program: Please help!
 Find entity by id
 DYNAMIC DATES IN MYSQL
 Difference between forward and sendRedirect
 Free Work at Home Info Pack - Find your dream job today

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






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