Datefield confussion

  1. #1

    Datefield confussion

    Hello.
    I'm trying to get the real value or text from a datefield but I always get it wrong.
    The format property seems to visually work, but when I try to get the .Text or .Value property, it always looks like "13/01/2010 12:00:00 a.m.", even when visually the control shows "2010-01-13", which is the format I need.

    I know this should be a really dumb mistake, but I can't find it.

    Any help is appreciated.

    Thanks in advance.
  2. #2
    Alright, I managed to get the short version of the date, but I still can't make this field to consider the .Format I specified.
    I need "yyyy-MM-dd" but the field returns "dd/MM/yyyy".

    EDIT:
    Forgot to mention, I used txtDate.SelectedDate.Date.ToShortDateString();
    This method should be able to receive a format parameter. Just saying.
  3. #3
    Quote Originally Posted by abelvn View Post
    Alright, I managed to get the short version of the date, but I still can't make this field to consider the .Format I specified.
    I need "yyyy-MM-dd" but the field returns "dd/MM/yyyy".

    EDIT:
    Forgot to mention, I used txtDate.SelectedDate.Date.ToShortDateString();
    This method should be able to receive a format parameter. Just saying.

    Rather than using in text format, use txtDate.SelectedDate.Date, then you'll be able to format it easily. Don't convert it to string. Hope it helps.
  4. #4
    Thanks for your response. It helped.

    I managed to get the date the way I need it, but I don't like the solution.
    I had to build the date from each part of the date:

    dateString = txtDate.SelectedDate.Date.Year.ToString() + "-" + txtDate.SelectedDate.Date.Month.ToString() + "-" + txtDate.SelectedDate.Date.Day.ToString();
    The Month property there returns "5" as the current month is may, instead of returning "05", which would be the normal behavior on most languages and database managers. I just wonder if that's gonna cause troubles later on.

    If anyone has another solution, please contribute.

    Thanks.
  5. #5
    Hello,

    You just need to pass a format into the .ToString() Method.

    Example

    dateString = txtDate.SelectedDate.ToString("yyyy-MM-dd");
    Hope this helps.
    Geoffrey McGill
    Founder
  6. #6
    YES.
    I knew this had the simplest solution.

    Thanks, Geoffrey.

Similar Threads

  1. [CLOSED] DateField
    By HOWARDJ in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 21, 2012, 4:34 AM
  2. Cannot set value of DateField
    By zhaoxl in forum 1.x Help
    Replies: 2
    Last Post: Feb 08, 2012, 6:48 AM
  3. DateField and ASP.NET MVC
    By DavidS in forum 1.x Help
    Replies: 2
    Last Post: Jul 06, 2011, 6:16 AM
  4. DateField Bug
    By dannyrih in forum 1.x Help
    Replies: 2
    Last Post: Jan 04, 2010, 3:06 PM
  5. DateField in a GridPanel
    By fabiomarcos in forum 1.x Help
    Replies: 6
    Last Post: Mar 05, 2009, 2:32 PM

Tags for this Thread

Posting Permissions