Results 1 to 10 of 10

Thread: Get dates between dates

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Get dates between dates

    I have a start date of: 02/13/2008 17:06
    I have an end date of: 02/16/2008 23:49

    I have been reading and reading but have no solution. I have two dates, a start and an end, which I have put at the top. How can I populate a listbox with the first item being the starting date and the last item being the end date and all items inbetween are dates and times incrementing in 1 minute values...?

    ie:
    02/13/2008 17:06
    02/13/2008 17:07
    02/13/2008 17:08
    02/13/2008 17:09
    ... all the way to
    02/16/2008 23:49

    ANY HELP IS GREATLY APPRECIATED!!!

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

    Re: Get dates between dates

    vb.net Code:
    1. Dim time As Date = startDate
    2.  
    3. Do
    4.     myListBox.Items.Add(String.Format("{0:d} {0:HH:mm}", time))
    5.     time = time.AddMinutes(1)
    6. Loop Until time > endDate
    Note that that format creates a string containing the standard short date form for the system, followed by a space, followed by hours and minutes in 24 hour format.
    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

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Get dates between dates

    A quick Google search yielded the members of a DateTime object. It includes a method called AddMinutes.

    Sounds like you can declare your start time, add 1 minute then add to the ListBox until it reaches the ending time. All that is required is a simple While loop.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: Get dates between dates

    thank you so much... my brain always wants to make it complicated and here it is being the easiest!!!

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

    Re: Get dates between dates

    The critically important first step is to ask yourself what you would do if you had to do the same thing manually, with pen and paper. The algorithm should be the same and implementing a simple algorithm is generally simple.
    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
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Get dates between dates

    Quote Originally Posted by if_then_else
    thank you so much... my brain always wants to make it complicated and here it is being the easiest!!!
    No problem. Thanks for giving me a disapproval rating

    heh
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

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

    Re: Get dates between dates

    Quote Originally Posted by kasracer
    No problem. Thanks for giving me a disapproval rating

    heh
    That's the pain you suffer when you point people to where they could have answered their question for themselves. I've felt it many times.
    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: Get dates between dates

    i gave everybody an approval? will do again, maybe i clicked wrong... my bad... i thought i gave everyone an approval rating as you all helped me in superman speed!!! i am a newbie to these forums so please forgive me... i tried to redo the rating but it wont allow...?
    Last edited by if_then_else; Feb 19th, 2008 at 02:10 AM.

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

    Re: Get dates between dates

    Quote Originally Posted by if_then_else
    i gave everybody an approval? will do again, maybe i clicked wrong... my bad... i thought i gave everyone an approval rating as you all helped me in superman speed!!! i am a newbie to these forums so please forgive me... i tried to redo the rating but it wont allow...?
    What's done is done. Just keep kas in mind and give him a couple of positive ratings in the future to make up for it. You can only rate each person 1 in 10, so you'll have to rate 20 people in total to make good. I'm sure kas is worth it though.
    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

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Get dates between dates

    Quote Originally Posted by if_then_else
    i gave everybody an approval? will do again, maybe i clicked wrong... my bad... i thought i gave everyone an approval rating as you all helped me in superman speed!!! i am a newbie to these forums so please forgive me... i tried to redo the rating but it wont allow...?
    No worries. I actually get quite a few disapproval ratings from new members when they tell me I helped them. I think the UI to give ratings is a little confusing to new members. Oh well.
    Quote Originally Posted by jmcilhinney
    What's done is done. Just keep kas in mind and give him a couple of positive ratings in the future to make up for it. You can only rate each person 1 in 10, so you'll have to rate 20 people in total to make good. I'm sure kas is worth it though.
    Heh, thanks. I'm worth all the ratings in the world! (which doesn't say much since ratings are worth $0, heh)

    EDIT: According to this thread I'm just a dope and you gave me a positive rating. It just won't show up yet.
    Last edited by Kasracer; Feb 21st, 2008 at 11:47 AM.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

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