Note that there are some explanatory texts on larger screens.

plurals
  1. PODate format with AM/PM designator is not correctly parse
    primarykey
    data
    text
    <p>I'm using this code to convert a string to date.</p> <pre><code>Dim outputDate as Date ' I have tried also with DateTime Dim inputStringDate as String = "January 14, 2013 PM" Dim dateFormat as string = "MMMM dd, yyyy tt" isValidDate = Date.TryParseExact(inputStringDate, dateFormat, New CultureInfo("en-US"), _ Globalization.DateTimeStyles.None, outputDate) ' isValidDate = true outputDate.ToString(dateFormat) 'January 14, 2013 AM </code></pre> <p>The issue is that "tt" is not recognize. The input text is "PM" (January 14, 2013 <strong>PM</strong>) but after parsing to date and applying it format I got "AM" (January 14, 2013 <strong>AM</strong>).</p> <p>The time of <code>outputDate</code> is 00:00:00, but I think it should be the PM default time 12:00:00.</p> <p>Environment: .Net 2.0 <br/> dtinfo.PMDesignator = PM <br/> dtinfo.AMDesignator = AM</p> <p>Thanks for your help</p> <p><strong>Overview</strong></p> <p>When trying to parse a date string with AM/PM designator (tt) but without time (hh:mm), for example “January 14, 2013 PM” (MMMM dd, yyyy tt), it seems that .NET Framework 2 would successful parse it but would ignore the AM/PM portion by setting the time as AM default, this is midnight (00:00). The solution is always giving it the time e.g. “hh:mm tt” or “HH:mm”.<br/> But using .Net Framework 4 in the same scenario, parsing the date string without time would fail; this is because .Net 4 would require the time and AM/PM designator (hh:mm tt), or the use of 24 format (HH:mm). Thanks to @Dave Michener for this (please review its comment) </p> <p>So in .Net 4 <br/> MMMM dd, yyyy tt --> Fails <br/> MMMM dd, yyyy hh:mm --> Fails <br/> MMMM dd, yyyy hh:mm tt --> Works <br/> MMMM dd, yyyy HH:mm --> Works</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload