SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy Date conversion from "April 12, 2012" to "2012-04-12"

    Hey everyone,
    Basically everything im trying to do is summed up in the subject line. I have a "DatePicker" control on my site, that when a date is selected, is displayed in the textbox as "April 12, 2012" or whatever the subsequent date may be. However, when I save this into my DB in a "Date" field, it saves in the format of "2012-04-12" which is fine with me, I just need to know the function in order to compare the DB value to a value in the DateSelector textbox. This is for a system I am building in case a user wants to "edit" a previously stored record, in case they change the subsequent date.

    I have tried using
    DateTime.Parse(PlanAdmit).ToString("YYYY-mm-dd")

    but get the error of;
    Conversion from string "YYYY-00-16" to type 'Date' is not valid.

    When the date selected was April, 16 2012

    Any help is much appreciated.
    Thank you for your time,
    NickG

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nickgirard21 View Post
    ... When the date selected was April, 16 2012 ...
    Did you mean "April 16, 2012"?

    Watch the case on your format. It's "yyyy" not "YYYY" and "MM" not "mm".

    Code Csharp:
    Console.WriteLine(DateTime.Parse("April 16, 2012").ToString("yyyy-MM-dd"));


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •