473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DateDiff

I have 2 variables - 'dt1' & 'dt2' - of type DateTime. Assume that one
of the values of 'dt1' (which is being retrieved from a DB table) is
27/12/2006 6:54:27 AM & the value of 'dt2' is the current date & time,
say, 30/12/2006 3:09:22 PM.

I have the following code which uses the built-in DateDiff function:

Dim dt1 As DateTime
Dim dt2 As DateTime

dt2 = DateTime.Now

If (DateDiff(DateInterval.Day, CDate(dt1), CDate(dt2)) < 3) Then
Label1.Text = "Less than 3 days have elapsed"
Else
Label1.Text = "3 or more than 3 days have elapsed"
End If

The DateDiff function above evaluates to 3 & since 3 < 3 evaluates to
False; the Else condition must get satisfied but when the value of
'dt1' is 27/12/2006 6:54:27 AM, then the If condition gets satisfied!

Why so?

Dec 29 '06 #1
1 1708
rn**@rediffmail.com wrote:
I have 2 variables - 'dt1' & 'dt2' - of type DateTime. Assume that one
of the values of 'dt1' (which is being retrieved from a DB table) is
27/12/2006 6:54:27 AM & the value of 'dt2' is the current date & time,
say, 30/12/2006 3:09:22 PM.

I have the following code which uses the built-in DateDiff function:

Dim dt1 As DateTime
Dim dt2 As DateTime

dt2 = DateTime.Now

If (DateDiff(DateInterval.Day, CDate(dt1), CDate(dt2)) < 3) Then
Label1.Text = "Less than 3 days have elapsed"
Else
Label1.Text = "3 or more than 3 days have elapsed"
End If

The DateDiff function above evaluates to 3 & since 3 < 3 evaluates to
False; the Else condition must get satisfied but when the value of
'dt1' is 27/12/2006 6:54:27 AM, then the If condition gets satisfied!

Why so?
You're right. I used pretty much the same code:

Dim dt1 As DateTime = CDate("12/27/2006 6:54:27 AM")
Dim dt2 As DateTime = CDate("12/30/2006 3:09:22 PM")

dt2 = DateTime.Now

If (DateDiff(DateInterval.Day, CDate(dt1), CDate(dt2)) < 3) Then
lbl1.Text = "Less than 3 days have elapsed"
Else
lbl1.Text = "3 or more than 3 days have elapsed"
End If

I also get the same, odd result. I am currently building a web app that
uses the datediff method and now I'm a bit speculative as to if my app
will work properly. I'll use DateInterval.Hour instead for my purposes.

As to why this happens, I don't know. I hope someone else on this board
does.
Dec 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CJM | last post by:
I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to show links that are created/modified from that date...
8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
6
by: Lofty | last post by:
Hi all. I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!) I need to work out the difference in days...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.