473,788 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16677
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*********@ya hoo.com> wrote in message
news:11******** *************@u 72g2000cwu.goog legroups.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(tstam p1),iso), char(time(tstam p1),usa)
from mytable
where....

In the expression 'char(date(tsta mp1), 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(tsta mp1), 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*********@ya hoo.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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
4575
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, m/d/Y',$row_rsquote); ?> but all I get is Monday, 01/18/2038.
4
7083
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 a',strtotime($row_rsSessions)); ?> If I give the timestamp a value of 8 I can get the date to work correctly
5
2822
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
5443
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 long way around the block. Is there a more direct way? Bill
2
2168
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. ============================================================= while (($data = fgetcsv($handle,5000, ",")) !== FALSE) { $mydate = $data; // here is the array value that holds the date }
2
1675
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 $dep_date;
2
1003
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, but the message box displays 1.20am !! Dim timestamp As Integer = 1159492831 Dim dt As Date = New System.DateTime(1970, 1, 1).AddSeconds(timestamp)
10
4026
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 problem. This function does not recognize time zones. How to adjust date to user's time zone? Is converting to timestamp() and then to format readable to visitors the one and only solution (e.g. strtotime() + date() OR DateTime object)? Perhaps,...
1
3446
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 when used with something like setLogStream(&std::cerr). However, I would like to add more context to the query logged. Specifically, I'd like to add the thread ID. So, instead of the query logged looking like:
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10112
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.