c# - How can I increment the hours in a date based on an interval in VB.NET -
user input:
dateinterval: 100714-10 interval: 2
output
datefrom: 07/10/2014 08:00 dateto: 07/10/2014 9:59
user input:
dateinterval: 100714-10 interval: 4
output
datefrom: 07/10/2014 06:00 dateto: 07/10/2014 9:59
the intervals 2,4,6,8,12, there should difference of hours between datefrom
, dateto
depending on interval chosen. example, if interval chosen 2 difference between hours should 2 hours. if interval 4 difference should 4 hours.
the code have written in button click
protected sub btnsubmitt_click(sender object, e eventargs) handles btnsubmitt.click dim _datetimeformatinfo new datetimeformatinfo() _datetimeformatinfo.shortdatepattern = "dd/mm/yyyy" _datetimeformatinfo.longdatepattern = "dddd, dd mmmm yyyy" _datetimeformatinfo.fulldatetimepattern = "dddd, dd mmmm yyyy hh:mm:ss" _datetimeformatinfo.monthdaypattern = "mmmm dd" _datetimeformatinfo.shorttimepattern = "hh:mm " _datetimeformatinfo.longtimepattern = "hh:mm" _datetimeformatinfo.dateseparator = "/" _datetimeformatinfo.dateseparator = "" _datetimeformatinfo.shortdatepattern = "dd/mm/yyyy" dim stra string = txtdateinterval.text dim split string() = new string(stra.length \ 2 + ((if(stra.length mod 2 = 0, 0, 1)) - 1)) {} integer = 0 split.length - 1 split(i) = stra.substring(i * 2, if(i * 2 + 2 > stra.length, 1, 2)) next dim s string = split(0) & "/" & split(1) & "/" & split(2) & "" & split(3) dim strintervaltype string = txtintervaltype.text txtdatefrom.text = datetime.parse(s, _datetimeformatinfo).tostring("mm/dd/yyyy hh:mm") txtdateto.text = datetime.parse(s, _datetimeformatinfo).tostring("mm/dd/yyyy hh:mm") end sub
class="lang-none prettyprint-override">dateinterval 10072014-10 intervaltype 2 datefrom 07/10/2014 08:00 dateto 07/10/2014 9:59
in above user giving values dateinterval , intervaltype
class="lang-none prettyprint-override">datefrom 07/10/2014 08:00 dateto 07/10/2014 9:59
how above output
to desired output , should want change
you can proceed below;
firstly, convert dateinterval datefrom, think doing correctly.
then using datefrom, need add together hours interval,
dateto = datefrom.addhours(interval)
your dateto add together hours interval datefrom. saying that, assume datefrom correct. :)
c# vb.net
No comments:
Post a Comment