I am trying to format a date and a time that comes in one column called DATE as DD/MM/YYYY (Varchar) and in another column called TIME as HH:MM:SS into one variable to inser
Somehow your LMONTH and LDAY values seem to be reversed as LMONTH is getting written as 31 and LDAY as 01 - which obviously incorrect. Check the data within your source table.
Look at the value:
'2013-31-01 16:00:40'
That's trying to use a month of 31.
It's not clear whether that just means your test data is wrong, or whether you need to change these lines:
SELECT SUBSTRING(DATE,3,2) FROM db.test_table INTO LMONTH;
SELECT SUBSTRING(DATE,1,1) FROM db.test_table INTO LDAY;
to:
SELECT SUBSTRING(DATE,1,2) FROM db.test_table INTO LMONTH;
SELECT SUBSTRING(DATE,4,2) FROM db.test_table INTO LDAY;
Note the change from 1 to 2 for the substring starting at 1 anyway, and the change of the second starting position from 3 to 4. You want two-digit month and day values, right? If your data format is actually D/M/YYYY (i.e. only using two digits when they're required) then you won't be able to use fixed substring positions.