Solved

visual studio dropdownlist calculate time values

Posted on 2014-02-14
4
208 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 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

16 Experts available now in Live!

Get 1:1 Help Now