Solved

visual studio dropdownlist calculate time values

Posted on 2014-02-14
5
275 Views
Last Modified: 2014-02-14
based on the current time (for example it is 4:43 PM)
my DDL shows items as follows:

NOW
4:58 PM
5:13 PM
5:28 PM
5:43 PM
5:58 PM
etc

but i would like the code to round up to the next whole 15 minutes to display instead

NOW
5:00 PM
5:15 PM
5:30 PM
5:45 PM
6:00 PM
etc

this code would have to be modified to calculate the round-up but I am not sure how to proceed

        ddlFullTime.Items.Add(New System.Web.UI.WebControls.ListItem("Now", dtNow.ToShortTimeString))
        dtMod = dtMod.AddMinutes(15)
        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
  • 3
  • 2
5 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 39860497
Try this:
ddlFullTime.Items.Add(New System.Web.UI.WebControls.ListItem("Now", dtNow.ToShortTimeString))
       dtMod =  DateTime.Now.AddMinutes(15 - (DateTime.Now.AddMinutes(15).Minute % 15))
        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)

Setting the first dtMod is the key;
0
 

Author Comment

by:Dale Massicotte
ID: 39860553
sami it does not accept % character

(not a valid character)
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 39860566
Ah...VB %=Mod
dtMod =  DateTime.Now.AddMinutes(15 - (DateTime.Now.AddMinutes(15).Minute Mod 15))
0
 

Author Comment

by:Dale Massicotte
ID: 39860595
You ARE the GURU!
0
 

Author Closing Comment

by:Dale Massicotte
ID: 39860640
please also look at

Q_28365465

similar topic
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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

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

13 Experts available now in Live!

Get 1:1 Help Now