Excel Date Format To Timestamp in DB2 SQL -


i have excel extract loading dates table not consistent format, making more challenging convert timestamp when copy table.

example dates are:

  1. 5/1/2015
  2. 5/15/2015
  3. 12/1/2015
  4. 12/15/2015

i need convert timestamp format. start, trying parse , concatenate date character type formatted timestamp.

the timestamp format needs be: yyyy-mm-dd hh24:mm:ss

our db2 instance old , not accept following functions: instr, locate_in_string

however, accept: locate

i had code working 2 of 4 date formats because specified actual numbers in parameters instead of using functions handle different date formats. after modifying query, in poorly displayed table, results are:

old date -- new date

4/3/2015 -- 2015-04-3/ 00:00:00

3/30/2015 -- 2015-03-30 00:00:00

12/31/2015 -- 2015-01-/3 00:00:00

12/3/2015 -- 2015-01-/3 00:00:00

the "--" in table above indicate different columns in table.

my current code is:

select startdate , right(ltrim(rtrim(startdate)), 4)     --year || '-' || right('00' || substr(startdate, 1, locate(startdate, '/', 1)+1), 2)  --month || '-' || left(substr(startdate, 3, locate(startdate, '/', 1)+2) || '00', 2)   --day || ' 00:00:00' startdate schema1.table1 

can help?

information our db2 version:

  • db2/nt sql08016
  • ibm data server driver jdbc , sqlj 4.13.127

one option might make db2 import or load command date format conversion. in table you're loading file into, define corresponding column have date data type, issue db2 command this:

import yourfile of del modified dateformat="mm/dd/yyyy"     replace yourtable (column1, column2, ...); 

after value date -- how should store dates anyway, not character strings, -- , can format liking using varchar_format() function.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -