Solved

visual studio dropdownlist calculate time values

Posted on 2014-02-14
4
206 Views
Last Modified: 2014-02-14
NOW
5:00 PM
5:15 PM
5:30 PM
5:45 PM
6:00 PM
etc

I want this to stop at 11:45 PM

here is existing code (seems i need some kind of do until loop perhaps?

        ddlFullTime.Items.Add(New System.Web.UI.WebControls.ListItem(dtMod.ToShortTimeString, dtMod.ToShortTimeString))
        dtMod = dtMod.AddMinutes(15)
        ddlFullTime.Items.Add(New System.Web.UI.WebControls.ListItem(dtMod.ToShortTimeString, dtMod.ToShortTimeString))
        dtMod = dtMod.AddMinutes(15)

Open in new window

0
Comment
Question by:Dale Massicotte
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 39860704
Try this:
ddlFullTime.Items.Add(New System.Web.UI.WebControls.ListItem("Now", dtNow.ToShortTimeString))
dtMod =  DateTime.Now.AddMinutes(15 - (DateTime.Now.AddMinutes(15).Minute Mod 15))
Dim target As DateTime = Convert.ToDateTime("11:45 PM")
While (dtMod.TimeOfDay < target.TimeOfDay)
    dtMod = dtMod.AddMinutes(15)
    ddlFullTime.Items.Add(New ListItem(dtMod.ToShortTimeString, dtMod.ToShortTimeString))
    
End While

Open in new window

0
 

Author Comment

by:Dale Massicotte
ID: 39860719
Why reinvent the wheel when you have guru_sami?

My brain is too slow and my loop sucked

Thanks for the code to sort of parse the date and time out.

I was almost there!
0
 

Author Closing Comment

by:Dale Massicotte
ID: 39860720
A+++++++++++++++++
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 39860744
Thanks. Glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now