Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,272 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,247 people online right now. Registration is fast and FREE... Join Now!




how to find time difference between two dates

 
Reply to this topicStart new topic

how to find time difference between two dates

deqwan22
13 Oct, 2008 - 04:56 AM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2008
Posts: 3

hi all.

i want to make a validation which a DOB must not exceed 13 years old by the current date,
if it is true, then something happen.



this is my code
CODE


        Dim dob As String
        Dim calcYr As Integer

        dob = 1 / 1 / 2000

        Dim date1 As Date
        Dim date2 As Date

        date1 = CDate(dob)
        date2 = Date.Today

        calcYr = DateDiff(DateInterval.Year, date1, date2)

        If calcYr < 13 Then
            Response.Write("success")
        Else
            Response.Write("failed")
        End If



but i got this error

Conversion from string "0.0005" to type 'Date' is not valid.


can somebody help me..


Conversion from string "0.0005" to type 'Date' is not valid.



User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Find Time Difference Between Two Dates
13 Oct, 2008 - 05:03 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You're getting that error because in this line

vb

dob = 1 / 1 / 2000


You're dividing 1 by 1 then dividing that by 2000, and that cannot be converted to a date. Try this

vb

Dim dob As String
Dim calcYr As Integer

dob = "1/1/2000"

Dim date1 As Date
Dim date2 As Date

date1 = CDate(dob)
date2 = Date.Today

calcYr = DateDiff(DateInterval.Year, date1, date2)

If calcYr < 13 Then
Response.Write("success")
Else
Response.Write("failed")
End If



User is offlineProfile CardPM
+Quote Post

deqwan22
RE: How To Find Time Difference Between Two Dates
13 Oct, 2008 - 05:51 PM
Post #3

New D.I.C Head
*

Joined: 29 Sep, 2008
Posts: 3

Thank you!
but it cames to me that if the person's dob is 11/15/1995,
the statement should return true. since by now the person age is still 12 and the he is one month early to become 13
so i think the statement
dateinterval.year
cannot be used am i?
so what function should i use?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 05:02AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month