|
-
Mar 27th, 2009, 10:37 PM
#1
Thread Starter
New Member
DateTimePicker Help
Hello, I'm trying to create some code that will take the date from one DateTimePicker (arrival date) and subtract it from another DateTimePicker(departure date) to determine the time stayed (hotel application). I also have to determine if, and how many days, are during the weekend (higher price).. and if the date is anytime May - September. This is for a college class, but my book doesn't really explain any of this, so any help would be greatly appreciated 
I also know some people want some sort of code so they aren't doing everything, but I haven't run into DateTimePicker yet so I have no clue what I'm doing, so even a website that explains how to do various functions with it would help
Thanks in advance
Dan
Edit: I'm using Visual Studio 2008 Express, so i believe this is the right thread =x
-
Mar 28th, 2009, 12:34 AM
#2
Re: DateTimePicker Help
Here's VB6 and Earlier Forum
Your problem isn't to take the date from a control
Code:
Dim MyDate As Date
MyDate = DTPicker1.Value
My advise is that You should read (a little) about Date Functions, they are easy and there are a lot of samples about them in the web, such as :
http://www.java2s.com/Tutorial/VB/01...-Functions.htm
Last edited by jggtz; Mar 28th, 2009 at 12:38 AM.
-
Mar 28th, 2009, 12:36 AM
#3
Re: DateTimePicker Help
Actually you missed it... you posted in the VB6 area... you want the .NET area... I'll let someone know it needs to be moved.
At anyrate, the DTP has a .Value property that will get you the date selected.
Had this been really for VB6, I would have then pointed you at the DateDiff function... but that won't do any good.
In .Net, you can actually do it like this:
Code:
Dim date1 As Date = CDate("1/1/2009")
Dim date2 As Date = CDate("12/31/2009")
Dim diff As TimeSpan = date2.Subtract(date1)
The TimeSpan object will then contain all of the info you need. There are a number of properties in there that will return the difference in hours, minutes, days, months, weeks and so on, poke around, look it up on MSDN and see what fits for you.
-tg
-
Mar 28th, 2009, 06:45 AM
#4
-
Mar 28th, 2009, 09:33 AM
#5
Re: DateTimePicker Help
 Originally Posted by techgnome
Actually you missed it... you posted in the VB6 area... you want the .NET area... I'll let someone know it needs to be moved.
At anyrate, the DTP has a .Value property that will get you the date selected.
Had this been really for VB6, I would have then pointed you at the DateDiff function... but that won't do any good.
In .Net, you can actually do it like this:
Code:
Dim date1 As Date = CDate("1/1/2009")
Dim date2 As Date = CDate("12/31/2009")
Dim diff As TimeSpan = date2.Subtract(date1)
The TimeSpan object will then contain all of the info you need. There are a number of properties in there that will return the difference in hours, minutes, days, months, weeks and so on, poke around, look it up on MSDN and see what fits for you.
-tg
Just one small point. Since .NET 2.0 the DateTime structure has supported arithmetic so you don't actually need to use the Subtract method. You can use the more natural subtraction operator:
vb.net Code:
Dim diff As TimeSpan = date2 - date1
-
Mar 28th, 2009, 09:47 AM
#6
Re: DateTimePicker Help
Ooohh... that's right, I keep forgeting that the operators have been overloaded for dates. ;P
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|