Click here to Skip to main content
15,301,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I have a issue, after a lot of tries and errors this is the final code, I also inserted a comment for each line to know about the structure of what I like to achieve in summary an auto-refreshing of all stored datetimes (with old timestamp and remaing days) with new one, all this with datetime.now to make the difference.
I put also the debug where program give me this error. How can I solve this?
https://i.imgur.com/WfSAZaR.png

What I have tried:

For i = 0 To ComboBox3.Items.Count -1    //the -1 is for next loop by all combobox stored items (in this case remaining time) 
            Dim d As DateTime = DateTime.Now
            Dim parsedate As String = ComboBox2.SelectedItem.ToString //this is where old datetime.now is stored
            Dim d2 As DateTime = DateTime.ParseExact(parsedate.ToString, "dd/MM/yyyy hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture) //now this string it's giving me an error to datatime not valid
            Dim dysdiff As Integer = (d - d2).Days //this one is to make the subtraction between old timestamp and new, the old one are stored in combobox2, both will have always same number of items
            ComboBox3.Items(i) = (365 - dysdiff).ToString + " Days" //this one is for substitute the old value of remaining time to new one, always in days format
            ComboBox3.SelectedIndex = i
        Next
Posted
Updated 16-Jan-22 10:27am
v2

1 solution

The custom datetime format string "hh:mm:ss" will fail when hh is not in the range [01,12]. What you most likely need is "HH:mm:ss" which accepts [01,24].

See Custom date and time format strings | Microsoft Docs[^]
   

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