473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 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 16647
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); ?> I tried doing this - <?php echo date('D,...
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 echo date('D,n-j-y h:i:s...
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 e.g. 13.02pm, 15/Feb/2005
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 "strftime('%y%m%d',localtime(os.stat('thefile'))", but this seems like a...
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 could be found in $array, for example....
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; $dep_date = $row; // print out date print...
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 error in my code?? The timestamp is for 11.20 am,...
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 today, the function returns "Today". There is one...
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 setLogStream(std::ostream *s); This works great...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.