472,353 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Formatting a Timestamp

I have a question that I'm hoping has an easy answer.

I'm working in DB2 V8.2 on AIX 5.3

I have a timestamp column (i.e. 4/26/2006 1:02:42.000000 PM) that I
want to return in a report from standard SQL.

The user does not want to see it as a timestamp. They want to see just
a regular date and time. When I convert to CHAR I get back the wrong
format (i.e. 2006-05-04-15.56). What I really want back is the
following:

2006-05-04 3:56 PM

Is there a built in date and/or time function that returns that result?

Thanks in advance!

Martin

May 4 '06 #1
4 16575
mghale wrote:
I have a question that I'm hoping has an easy answer.

I'm working in DB2 V8.2 on AIX 5.3

I have a timestamp column (i.e. 4/26/2006 1:02:42.000000 PM) that I
want to return in a report from standard SQL.

The user does not want to see it as a timestamp. They want to see just
a regular date and time. When I convert to CHAR I get back the wrong
format (i.e. 2006-05-04-15.56). What I really want back is the
following:

2006-05-04 3:56 PM

Is there a built in date and/or time function that returns that result?

Thanks in advance!

Martin


Try date() and time() functions to extract date and time portions of timestamp:

D:\Working>db2 values current timestamp

1
--------------------------
2006-05-04-19.35.48.354001

1 record(s) selected.
D:\Working>db2 values date(current timestamp)

1
----------
05/04/2006

1 record(s) selected.
D:\Working>db2 values time(current timestamp)

1
--------
19:36:23

1 record(s) selected.
D:\Working>
Jan M. Nelken
May 4 '06 #2

"mghale" <ma*********@yahoo.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
I have a question that I'm hoping has an easy answer.

I'm working in DB2 V8.2 on AIX 5.3

I have a timestamp column (i.e. 4/26/2006 1:02:42.000000 PM) that I
want to return in a report from standard SQL.

The user does not want to see it as a timestamp. They want to see just
a regular date and time. When I convert to CHAR I get back the wrong
format (i.e. 2006-05-04-15.56). What I really want back is the
following:

2006-05-04 3:56 PM

Is there a built in date and/or time function that returns that result?

You can use a combination of built-in functions to get the desired result;
just concatenate the different parts together to get the format you want.
Something like this, assuming the column containing the timestamp is called
tstamp1:

select char(date(tstamp1),iso), char(time(tstamp1),usa)
from mytable
where....

In the expression 'char(date(tstamp1), iso)', the date() function obtains
the date portion (year, month, and day) of the timestamp; the char()
function with the 'iso' argument tells DB2 to format the date using the ISO
standard, i.e. 4 digit year, 2 digit month, 2 digit day, separated by
dashes.

In the expression 'char(time(tstamp1), usa)', the time() function obtains
the time portion of the timestamp; the char() function with the 'usa'
argument tells DB2 to format the time using the US standard, i.e. hours,
followed by a colon, minutes, followed by a space and AM or PM.

--
Rhino
May 5 '06 #3
Thanks so much for the replies. The iso/usa options worked perfectly
to get exactly what I was wanting returned.

Thanks again. Your help and information is greatly appreciated.

Martin

May 5 '06 #4

"mghale" <ma*********@yahoo.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Thanks so much for the replies. The iso/usa options worked perfectly
to get exactly what I was wanting returned.

Thanks again. Your help and information is greatly appreciated.

You're very welcome!

--
Rhino
May 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RT | last post by:
How would I format a timestamp which is used to show when a quote was created in a record set. This is the echo - <?php echo($row_rsquote); ?>...
4
by: RT | last post by:
If anyone can help that would be great. Iım trying to format a timestamp from my MySQL table (sessions) Hereıs the code Iım using: <?php...
5
by: Martin Lucas-Smith | last post by:
I have a string saved in the format produced by date ('Ymd-Hms') e.g. 20050215-130257 Can anyone suggest the easiest way to present this as...
2
by: WmGill | last post by:
I want to write a script that Among other things) renames a file based on it's timestamp. I can get the date info using...
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date...
2
by: laredotornado | last post by:
Hello, Using PHP 4, MySQL 4, I am getting a date field $dbh = executeSQL($query); while ($row = mysql_fetch_array($dbh)) { $offer_id = $row;...
2
by: linuxnooby | last post by:
Hi I am trying to display a unix timestamp as a time of day. I can do this but I lose 10 hours. Is this something do with locale or is there an...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as...
1
by: AJG | last post by:
Hi there. I am using a library called SOCI that has a method to set a stream which it uses to log SQL queries. The signature is as follows: void...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.