insert date in desired format m-d-Y

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    insert date in desired format m-d-Y

    hi there i am inserting a desired formated date ie
    m-d-y --------2-23-2008
    into mysql database in which i have the field named Bill_date which has the format Date here is my query
    Code:
    $sqlAS="insert into sale_rec(Bill_no,Bill_date,Cust_name,Mop,Con_per,Con_no,Code_no,Prt_no,Stk_avl,Stk_req,U_prc,T_prc,Prd) 
    	values('$billno',DATE_FORMAT('$seldate','USA'),'$cname','$mop','$cper','$cno','$codeno','$prt','$stkavl','$stkreq','$uprc','$tprc','$prd')";
    i have swapped he statement DATE_FORMAT('$s eldate','USA') to DATE_FORMAT('US A','$seldate') also but it still gives me the same error the date i am posting the date from a form and it is properly posted into this page and is showing the value in the variable $seldate
    but i am recieving the following error
    Code:
    Column 'Bill_date' cannot be null
    insert into sale_rec(Bill_no,Bill_date,Cust_name,Mop,Con_per,Con_no,Code_no,Prt_no,Stk_avl,Stk_req,U_prc,T_prc,Prd) values('1007',DATE_FORMAT('02-23-2008','USA'),'sameeer','CHEQUE','oemr','0321','1000','CSV-4456','13','1','500','500','WATER_FILTER')
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    DATE_FORMAT() does not have the 'USA' attribute. That option is used in function GET_FORMAT().

    You'll have to use
    Code:
    INSERT ........ STR_TO_DATE('$seldate',  '%d-%m-%Y');
    Ronald

    Comment

    • mwasif
      Recognized Expert Contributor
      • Jul 2006
      • 802

      #3
      You can not insert date in m-d-y format. DATE only accepts yyyy-mm-dd. But you can use DATE_FORMAT() and other date functions to get the desired output.

      Comment

      • omerbutt
        Contributor
        • Nov 2006
        • 638

        #4
        Originally posted by mwasif
        You can not insert date in m-d-y format. DATE only accepts yyyy-mm-dd. But you can use DATE_FORMAT() and other date functions to get the desired output.
        thnaks alot buddies i knew that it wont be possble but as searching to do so cbecause i am a new beee to mysql and php used to work in access and asp before.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          You are welcome. See you next time around.

          Ronald

          Comment

          Working...