Solved

visual studio dropdownlist calculate time values

Posted on 2014-02-14
5
276 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net VB.net Errors when sending data to SQL 5 20
ASP.NET gridview select textbox on focus 2 34
imap mails 1 22
ASP.NET MVC -Add authentication 2 21
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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