Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date formats in c#
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01534833
Message ID:
01534853
Views:
62
>>>Hi.
>>>
>>>VFP
>>>x={^2011-05-10} ALWAYS returns 10th May 2011 no matter what the culture is
>>>
>>>C#
>>>dateValue = DateTime.Parse("2011-05-10");
>>> Does this ALWAYS return 10th May, 2011 or are there instances when I could get 5th October 2011 ?
>>> If so, can it be made unambiguous , similar to the ^ in VFP
>>>Tia
>>>Gerard
>>
>>It will always return May because there is not such date format like ydm.
>
>Are you sure ?
>
>From docs :
>"The string s is parsed using formatting information in the current DateTimeFormatInfo object, which is supplied implicitly by the current thread culture"
>
>AFAIK it's perfectly possible to set a short date pattern for DateTimeFormatInfo that would produce year,day,month. Similar to:
>DateTime.Now("yyyy/dd/MM");



If you set the date to an esoteric format, you have to assume it! To prevent that, you can query the current format and use it in TryParseExact.

but the format ydm does not exist in the list of formal format which you can obtain using the following code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()

        For Each ci As CultureInfo In CultureInfo.GetCultures(CultureTypes.AllCultures)
            If Not ci.IsNeutralCulture Then
                If Not ListBox1.Items.Contains(ci.DateTimeFormat.LongDatePattern) Then
                    ListBox1.Items.Add(ci.DateTimeFormat.LongDatePattern)
                End If
            End If
        Next

        ListBox1.Sorted = True
    End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform