locked
problem with inserting date in mysql RRS feed

  • Question

  • User2031860760 posted

    hello everyone i am trying to store a date in database mysql....but mysql accepts yyyy-MM-dd and i have a javascript calender which returns in dd-MMM-yyyy format....so its allowing me to store it.....so please tell about the datatype if i am taking it wrong m using datetime for storing the date....so please tell what to do with an piece of example....thnx in advance

    Friday, June 1, 2012 7:18 AM

All replies

  • User-126879547 posted

    Hai

    Change Dtatype DateTime to Date only...

    thank u

    Friday, June 1, 2012 7:20 AM
  • User2031860760 posted

    still the problem is same its not converting the format of the date....so MySql is not allowing to insert the data

    Monday, June 4, 2012 1:31 AM
  • User-1129879462 posted

    Try Set DateFormat statement

    -- Set date format to day/month/year.
    SET DATEFORMAT dmy;
    GO
    DECLARE @datevar datetime2 = '31/12/2008 09:01:01.1234567';
    SELECT @datevar;
    GO
    -- Result: 2008-12-31 09:01:01.123
    SET DATEFORMAT dmy;
    GO
    DECLARE @datevar datetime2 = '12/31/2008 09:01:01.1234567';
    SELECT @datevar;
    GO
    -- Result: Msg 241: Conversion failed when converting date and/or time -- from character string.
    
    GO
    Monday, June 4, 2012 1:46 AM
  • Monday, June 4, 2012 1:47 AM
  • User2031860760 posted

    thnx for helping me but its not working when i used Format(DateTimePicker1.Value, "yyyy-MM-dd") its giving  syntax error saying 'this name Format does not exist in current context' so if you can help me lil more it would be great for me....thnx in advance...:)

    Monday, June 4, 2012 2:22 AM
  • User-126879547 posted

    in your code, you can do the following:

    string theDate = dateTimePicker1.Value.ToShortDateString();

    or, if you'd like to specify the format of the date:

    string theDate = dateTimePicker1.Value.ToString("yyyy-MM-dd")
    Monday, June 4, 2012 2:34 AM
  • User2031860760 posted

    in this case it will be a string and i have to store it in date datatype....so it wont work even if we will parse it to date i think it will give me the format in dd/mm/yyyy...i think i have already tried it....btw thnx for replying...:)

    Monday, June 4, 2012 2:41 AM
  • User-1598965247 posted

    your javascript calendar might have a property to set date format to ymd. Check

    Wednesday, June 6, 2012 7:29 AM