Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two dates field
first : confirmed delivery date
second :real delivery date
i want to decrease confirmed delivery date from real delivery date to calculate delay time
can you help me please ?

What I have tried:

How to Compare between Two Dates in vb.net ?
Posted
Updated 16-Mar-16 2:58am

Assuming you have the dates in VB, they should be in DateTime values.
So...
VB
Dim diff As Timespan = realDeliveryDate - confirmedDeliveryDate

If you don;t have them as DateTime values, then convert them to DateTime using DateTime.TryParse
If they are in SQL, then again, they should be DATE or DATETIME columns, in which case
SQL
SELECT DATEDIFF(dd, realDeliveryDate, confirmedDeliveryDate) FROM MyTable
Where "dd" selects days (but see DATEFIFF for other options).
If they are stored in SQL as strings, then change your datasbe to use DATE or DATETIME columns instead as it will only cause major hassles if you don't!
 
Share this answer
 
Alternate to above solution you can use, .Subtract method of date class.
look at below code
VB
Dim dateOne = DateTimePicker1.Value
Dim dateTwo = DateTimePicker2.Value
Dim diff As TimeSpan = dateTwo.Subtract(dateOne)
Dim years As Double = diff.TotalDays / 365
txtyrs.Text = years.ToString
txtmonsh.Text = (years * 12).ToString
txtdays.Text = diff.TotalDays.ToString

Hope it helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900