473,396 Members | 1,892 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,396 software developers and data experts.

Convert TIMESTAMP to DATE

Hi,

I can easily convert a TIMESTAMP to a DATE which will give me results
in the format 'DD/MM/YYYY' however, what I want to do is convert the
TIMESTAMP to just 'MM/YYYY' or even better 'MMM/YYYY'.

I tried using the cast function as follows but it failed.

CAST(CURRENT TIMESTAMP AS DATE FORMAT 'mm/yy')

What am I doing wrong?

Thanks

May 31 '07 #1
5 77100
whitsey wrote:
Hi,

I can easily convert a TIMESTAMP to a DATE which will give me results
in the format 'DD/MM/YYYY' however, what I want to do is convert the
TIMESTAMP to just 'MM/YYYY' or even better 'MMM/YYYY'.

I tried using the cast function as follows but it failed.

CAST(CURRENT TIMESTAMP AS DATE FORMAT 'mm/yy')

What am I doing wrong?

Thanks
It isn't pretty - and formatting for a single digit months can be
improved bu using SUBSTR, but try this:
cast(month(current timestamp) as char(2)) concat '/' concat
cast(year(current timestamp) as char(4));
Jan M. Nelken
May 31 '07 #2
Another examples are ....
1)
SUBSTR(DIGITS(MONTH(CURRENT TIMESTAMP)),9,2)
||'/'||SUBSTR(DIGITS(YEAR(CURRENT TIMESTAMP)),7,4)

2)
CAST(INSERT(CHAR(DATE(CURRENT TIMESTAMP),USA),3,3,'') AS CHAR(7) )

3)
SUBSTR(REPLACE(CHAR(DATE(CURRENT TIMESTAMP),EUR),'.','/'),4,7)

4)
TRANSLATE('FG/ABCD', CHAR(CURRENT TIMESTAMP), 'ABCD-FG')

May 31 '07 #3
On May 31, 6:41 pm, Tonkuma <tonk...@jp.ibm.comwrote:
Another examples are ....
1)
SUBSTR(DIGITS(MONTH(CURRENT TIMESTAMP)),9,2)
||'/'||SUBSTR(DIGITS(YEAR(CURRENT TIMESTAMP)),7,4)

2)
CAST(INSERT(CHAR(DATE(CURRENT TIMESTAMP),USA),3,3,'') AS CHAR(7) )

3)
SUBSTR(REPLACE(CHAR(DATE(CURRENT TIMESTAMP),EUR),'.','/'),4,7)

4)
TRANSLATE('FG/ABCD', CHAR(CURRENT TIMESTAMP), 'ABCD-FG')
THanks For that - works like a charm however, the sort order that the
dates are returned in the order of the months of the year i.e. Jan07,
Feb-07 ... Nov-06, Dec-06.

How do I sort it chronologically? i.e. Jun-06, Jul-06 ... Apr-07,
May-07

May 31 '07 #4
See my note to teh other thread. Use INTEGER(date)

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 31 '07 #5
I thought that you want to get the result with format 'mm/yyyy'.
But, if you don't stic that format and want to group by and sort order
of year/month,
followings would be the answer.

1)
INTEGER(DATE(CURRENT TIMESTAMP))/100
Result: yyyymm (INTEGER)

2)
SUBSTR(CHAR(CURRENT TIMESTAMP),1,7)
Result: 'yyyy-mm' (CHAR(7))

May 31 '07 #6

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

Similar topics

1
by: Bob | last post by:
Trying to convert timestamp data to date data (without the time in hours/mins/secs), does only seem to work with TO_DATE(mydate; 'yyyymmdd'). But I do not want a string, but a real date like...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
by: ABC | last post by:
How to convert a date string to datetime value with custom date format? e.g. Date String Date Format Result (DateTime value) "05/07/2004" "MM/dd/yyyy" May 7, 2004 "01062005" ...
1
by: h_ghanaty | last post by:
how i can convert gregorian date to jalaly(Iran date) with vb.net
1
by: Raja | last post by:
Hi Anyone has any idea of how to convert Julian Date (eg. 12744057862..) to a VB.NET date time. Thanks in advance.
1
by: Sam | last post by:
How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on following guideline found at Internet? To convert Julian date to Gregorian date: double JD = 2299160.5; double Z =...
4
by: Daniel Kaseman | last post by:
How do I convert a date into a serial number? (I'm trying to enter a FROM date and a TO date, then make my PROGRESS BAR show how close I am to the TO date.) get it? I know that MS Excel...
2
by: Kakishev | last post by:
I have a problem at how best to convert a Date into a text field and keep the format dd/mmm/yyyy (01-FEB-2007). The problem is that dates are imported from SQL into an access front end Database....
3
by: lyne_asp | last post by:
Please help me to convert excel date to asp date. Here is my code objConnEx.open "Provider=Microsoft.Jet.OLEDB.4.0;Data...
1
by: smdmca | last post by:
I have Julian date, I want to convert it into date. Is there any function in MySql to convert Julian date to date eg- Julian Date- 2455116 Date - Oct - 12, 2009
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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,...

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.