Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Military Time format, How can I add + 1 to days in date format of mm/dd/yyyy, if hours reach 24.
Textbox7.Text Represents the result
time.Text represtents ##.## mm/dd/yyyy - this is my problem

VB
TextBox7.Text = Format(Val(TextBox6.Text) + Val(Strings.Left(time.Text.Trim,5)),"##.00")
      'if minutes reach 60"               
If Val(TextBox7.Text.Trim.Split(".")(1)) >= 60 Then
         TextBox7.Text = Val(TextBox7.Text.Trim.Split(".")(0)) + 1 &             "." & Val(TextBox7.Text.Trim.Split(".")(1) - 60) & Format(Now, "MM/dd/yyyy")Else
         TextBox7.Text = Format(Val(TextBox6.Text) + Val(Strings.Left(time.Text.Trim, 5)),"##.00") & Strings.Right(time.Text.Trim, 11)
End If


       'Do here, if hours reach 24"  
If Val(TextBox7.Text.Trim.Split(".")(0)) >= 24 Then
TextBox7.Text = Val(TextBox7.Text.Trim.Split(".")(0)) - 24 & "." & Val(TextBox7.Text.Trim.Split(".")(1)) & Format(Now, "MM/dd/yyyy")End If
Posted
Updated 17-Mar-14 21:03pm
v2
Comments
Asgard25 18-Mar-14 3:45am    
Have you tried giving the time to a string value(e.g sTime) and then, sTime = sTime.addDays(+1) ?
romjoy hipos 18-Mar-14 19:43pm    
This is my updated code:

Dim xDate As Date = Format(CDate(Strings.Right(time.Text.Trim, 11)), "MM/dd/yyyy")

If Val(TextBox7.Text.Trim.Split(".")(0)) > 24 Then

TextBox7.Text = Val(TextBox7.Text.Trim.Split(".")(0)) - 24 & "." & Val(TextBox7.Text.Trim.Split(".")(1)) & " " & DateAdd(DateInterval.Day, 1, xDate)

End If

The output is now correct, but the format output is 1.3903 3/19/2014.. there is always 03 or extra two characters before date format, like this format: #.##03 ##/##/##

1 solution

You should convert the text values to DateTime[^] objects using one of the Parse methods, then you can just use the AddDays method to increment it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900