Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-01843: not a valid month when insert a date in oracle

I'm trying to insert a row in oracle database and when i try with the date i have the errore in title. My date is DD/MM/YYYY HH:MM:SS (example 25/01/2013 12:07:19)

edit for better explain: i have an android application and want to insert a row in oracle database by php.
in Php i have:

$sqlString = sprintf("INSERT INTO GUASTI (%s, %s, %s, %s, %s, %s) 
                      VALUES ('%s', '%s', '%s', '%s', '%s', '%s')"
                      ,'guasto','tipo','data', 'localita', 'indirizzo_id', 'utente_id',
                       $array['guasto'], $array['tipo'], $array['data'], $array['localita'], $idUtenti, $idIndirizzo);

where $array['data'] is 25/01/2013 12:07:19

p.s. i know that there are security problems there but it is not a problem for now.

like image 419
Atomico Avatar asked Dec 26 '22 12:12

Atomico


2 Answers

MM is for month. Use MI for minutes.

You have

HH:MM:SS

every time where the minutes are greater than 12 will trigger the error as you are telling Oracle to interpret them as months.

You are also using HH without am/pm (in your example you just used 12). If you are using a 24 format use HH24

DD/MM/YYYY HH24:MI:SS

or if you want the 12-hour format

DD/MM/YYYY HH:MI:SSAM

and then

02/01/2013 07:42:00am

Edit

You are inserting the date with the default format which is MM/DD/YYYY (american standard): 25 is not a valid month. You can use the TO_DATE function

'TO_DATE(' . $array['data'] . ', DD/MM/YYYY HH24:MI:SS)'
like image 181
Matteo Avatar answered Jan 31 '23 07:01

Matteo


Use TO_DATE('20/08/2012 09:00:00','DD/MM/YYYY HH24:MI:SS') while inserting date for more details see link Oracle Error

like image 27
Sonal Patil Avatar answered Jan 31 '23 08:01

Sonal Patil