One for the IT crow...
 

MegaSack DRAW - This year's winner is user - rgwb
We will be in touch

[Closed] One for the IT crowd - CAST and timestamps

13 Posts
12 Users
0 Reactions
76 Views
Posts: 13421
Full Member
Topic starter
 

I run:

SELECT TIMESTP, CAST(TIMESTP AS STRING) FROM ....

I get back :

2006-05-11 10:48:10.0, 2006-05-11-10.48.10.000000

Notice the extra - between the month and the hour... The bleeding database does when we try and use it in a select. Any way of controlling the format of the string when converting from Timestamp to a string? The same thing happens when we use Convert.

It is running in Metamatrix through a JDBC driver onto a DB2 database.


 
Posted : 15/04/2010 2:38 pm
Posts: 2390
Free Member
 

Good grief.


 
Posted : 15/04/2010 2:49 pm
Posts: 13421
Full Member
Topic starter
 

Look, I am stuck in Switzland so I have to do something. Basically for some reason we have to convert a timestamp into a string and store it in a table. We then extract it from that table, convert it back into a time stamp and use that to select from another table. It sticks the bloody dash in there so never finds any matches from the select.

Please can someone do my work for me and resolve this.


 
Posted : 15/04/2010 2:52 pm
Posts: 3297
Full Member
 

looked on google and it seems people have done it by either string manipulation or building up a string from the component date parts. not nice.

but I aint no DB2 expert, just bored


 
Posted : 15/04/2010 3:03 pm
Posts: 2
Free Member
 

I would build up the component parts and concatenate them together...

can you not just split it in 2 and then join without the -. Left(your_string,x)

right(your_string,x)

then left||right??


 
Posted : 15/04/2010 3:08 pm
Posts: 1
Free Member
 

upgrade to oracle 🙂


 
Posted : 15/04/2010 3:10 pm
Posts: 0
Free Member
 

Get an expensive consultant in who knows what they're doing.


 
Posted : 15/04/2010 3:11 pm
Posts: 0
Free Member
 

Basically for some reason we have to convert a timestamp into a string and store it in a table. We then extract it from that table, convert it back into a time stamp and use that to select from another table. It sticks the bloody dash in there so never finds any matches from the select.

Now that just seems stoopid.

I'm with soma_rich, split it, then rejoin it. Not the best solution, really you should be looking why its putting a "-" there.

But i could be talkin out me arse! I aint done programming for 10+ years!


 
Posted : 15/04/2010 3:16 pm
Posts: 12080
Full Member
 

Try concatenating using YEAR, MONTH etc. functions:

YEAR (current timestamp)
MONTH (current timestamp)
DAY (current timestamp)
HOUR (current timestamp)
MINUTE (current timestamp)
SECOND (current timestamp)
MICROSECOND (current timestamp)


 
Posted : 15/04/2010 3:20 pm
Posts: 0
Free Member
 

Use something better than DB2. For Gods sake man, this some sort of inventory system for Noahs Ark?


 
Posted : 15/04/2010 3:25 pm
Posts: 0
Free Member
 

as said - split and rejoin - if the string is uniform in length this should work:

[code]SUBSTRING(CAST(TIMESTP AS STRING),1,10)+' '+SUBSTRING(CAST(TIMESTP AS STRING),12,100)[/code]

from the [url= http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_datetimestringrepresentation.htm ]tech document[/url] it looks like the extra dash is default behaviour


 
Posted : 15/04/2010 3:52 pm
Posts: 12080
Full Member
 

Use something better than DB2. For Gods sake man, this some sort of inventory system for Noahs Ark?

Blah blah blah, you'll be recommending Oracle next. My client's got Oracle, 2500 bloody tables for the main user, the other user apparently doesn't know what a primary key is, so forget about referential integrity...

I've seen better Access databases.


 
Posted : 15/04/2010 3:59 pm
Posts: 0
Free Member
 

why do you want to store it as a string?

you want a PICK-type database 😉

in PICK, dates are plus or minus the number of days since (or before) 31/12/1967; times are seconds after midnight. And the system has operators that convert them into something readable in whatever format you like.

Tables? What are they? PICK has 'files' instead of Tables, and individual
records rather than 'rows'. Each record is multidimensional too...


 
Posted : 15/04/2010 7:29 pm
Posts: 5755
Full Member
 

When you to string the date can you not set the format of the date as a parameter of the to string function, or am I just thinking too much like a pl/sql developer?
😛


 
Posted : 15/04/2010 7:30 pm