Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello CodeProject,

I`m migrating access database to vb.net.
I have employee database with a few DateTimePickers, textboxes, and comboboxes.
In access I have formulas in textbox's control source like this, and it works:
txtDayCalculation
=DateDiff("d",txtDateofHire, txtManualDate)
txtYear
=Int(txtDayCalculation/365)
txtMonth
=Int((txtDayCalculation-(txtYear*365))/30) 
txtDay
=((txtDayCalculation-txtYear*365))-(txtMonth*30)


So, I have trying to do also in vb.net, but NOT successful.
Maybe my approach to write a code is wrong.

Anyway, I have code like this:
me.txtDayCalculation.text = DateDiff("d",txtDateOfHireDateTimePicker, txtManualDateDateTimePicker)


Please someone to check code, and give me corrections.
Thank you in advance for help to anyone
Posted
Updated 15-Jan-11 2:08am
v3
Comments
Dalek Dave 15-Jan-11 8:08am    
Edited for Spelling and Readability.

read this article at the bottom is a great example showing what your after

MSDN : datediff function[^]
 
Share this answer
 
Comments
Dalek Dave 15-Jan-11 8:08am    
Good Link
Try using the TimeSpan[^] object.
 
Share this answer
 
Comments
Dalek Dave 15-Jan-11 8:08am    
Sage Advice
If you need to get the number of days between the two days, you can simply use this:

int daysDifference = (datePicker1.Value - datePicker2.Value).Days;


This will give the whole number for days. If you need excat number, use TotalDays instead of Days.
 
Share this answer
 
Comments
Dalek Dave 15-Jan-11 8:09am    
Fair emough answer.
Thank you to all for tips, help, and so quick replies.

I have found this. Just have add Value.Date

DateDiff(DateInterval.Day,DateTimePicker1.Value.Date, DateTimePicker2.Value.Date)
 
Share this answer
 
Comments
Dalek Dave 15-Jan-11 8:09am    
That'll do!

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