Results 1 to 6 of 6

Thread: DateTimePicker Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    4

    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

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    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.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DateTimePicker Help

    Moved To VB.NET

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DateTimePicker Help

    Quote Originally Posted by techgnome View Post
    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:
    1. Dim diff As TimeSpan = date2 - date1
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: DateTimePicker Help

    Ooohh... that's right, I keep forgeting that the operators have been overloaded for dates. ;P

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width