Solved

visual studio dropdownlist calculate time values

Posted on 2014-02-14
5
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

622 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