Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27201

VS 2008 Construct date from string

$
0
0
Hello,
I have situation with datetimepicker where I try to set a datetime value (or maybe text) from string.

Such this:
Code:

      With dtp_datum1
            '.Text = DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 00:00:00" ' this works on win7
            .Value = CDate(DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 00:00:00")
            .Format = DateTimePickerFormat.Custom
            .CustomFormat = "dd.MM.yyyy. HH:mm:ss tt"
            .ShowUpDown = False
        End With

        With dtp_datum2
            '.Text = DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 23:59:59.9999"
            .Value = CDate(DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 23:59:59.9999")
            .Format = DateTimePickerFormat.Custom
            .CustomFormat = "dd.MM.yyyy. HH:mm:ss tt"
            .ShowUpDown = False
        End With

All variants, with value and with text work on win7 OK but no one want on windows XP.
Cultuture seem's to be equal at both: "hr-HR", "en-US". I check with this code:
Code:

        Dim thisCulture As String = Globalization.CultureInfo.CurrentCulture.ToString
        Debug.Print(thisCulture)

        Dim thisCultureUI = Thread.CurrentThread.CurrentUICulture.ToString
        Debug.Print(thisCultureUI)

Also, There are times when I have to construct other dates and times from string in my program.
By comming to this lines of code on XP program crashes with exceprion: "String was not recognized as a valid Datetime"
If I try to change type to date with CDate I get error: "Conversion from string "06.01.2013. 00.00.00" to type 'Date' is not valid."

What may be a problem here and how to solve this?

Viewing all articles
Browse latest Browse all 27201


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>