DateField Problem - Wrong SelectedDate regardless of the format

  1. #1

    DateField Problem - Wrong SelectedDate regardless of the format

    Hello,

    I'm using the DateField to allow the user select a particualr date. I'm setting the Format of the DateField to dd-m-yyyy. The selected date is displayed properly in the DateField box, but when getting the value of the selected date into, for example, a label as the following:
    lblDate.Text = dtFrom.SelectedDate.Date.ToString();
    the value is incorrect, for example, if the the selected date was 23-04-2009 the label text would be 1/23/2009, now regardless of the format, I didn't select the 1/23/2009 date, instead it was 23-04-2009. Thanks in advance
  2. #2

    RE: DateField Problem - Wrong SelectedDate regardless of the format

    Am also Having the same problem.please help.

    Regards.
  3. #3

    RE: DateField Problem - Wrong SelectedDate regardless of the format

    Hi,

    Please note that you must set .NET compatible date format.


    dd-m-yyyy is mean for .NET


    dd - *Represents the day of the month as a number from 01 through 31. A
    single-digit day is formatted with a leading zero.


    m -*Represents the minute as a number from 0 through 59. The minute represents whole
    minutes that have passed since the last hour. A single-digit minute is formatted
    without a leading zero. For more information about using a single format
    specifier


    yyyy -*Represents the year as a four-digit number. If the year has more than four
    digits, only the four low-order digits appear in the result. If the year has
    fewer than four digits, the number is padded with leading zeros to achieve four
    digits.


    I think you need use the following format


    dd-MM-yyyy


    Also it can be usefull to hardcore "-" date separator to avoid it's cahnge by .NET (it depend from current culture)
    So, you can try


    DateField1.Format = @"dd\-MM\-yyyy";


    <div id="snippetGroup1">
    <div class="libCScode" id="ctl00_LibFrame_MainContent_ctl146_VisualBasic " style="DISPLAY: none">
    <div class="CodeSnippetTitleBar">
    <div class="CodeDisplayLanguage">Visual Basic

    <div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_LibFrame_MainContent_ctl146V isualBasic');">
    Copy Code</a>


    <div dir="ltr">Dim date1 As Date = #1/2/2008 6:30:15AM#

    Console.WriteLine(date1.ToString("dd, MM", _
    CultureInfo.InvariantCulture))
    ' 02, 01


  4. #4

    RE: DateField Problem - Wrong SelectedDate regardless of the format

    Thanks vladimir, I tried your suggestion and now the date is saved correctly. Thanks again and you can mark this as solved.

Similar Threads

  1. [CLOSED] Wrong Date Format on the store
    By ViDom in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 25, 2011, 9:56 PM
  2. [CLOSED] DateField data format problem
    By asztern in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 08, 2010, 9:36 PM
  3. DateField - SelectedDate problem
    By Puia in forum 1.x Help
    Replies: 3
    Last Post: Sep 14, 2009, 12:16 PM
  4. Replies: 4
    Last Post: Mar 18, 2009, 3:43 AM
  5. [CLOSED] Get SelectedDate in DateField
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 16, 2008, 6:13 AM

Posting Permissions