473,889 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 78089
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(curr ent timestamp) as char(2)) concat '/' concat
cast(year(curre nt timestamp) as char(4));
Jan M. Nelken
May 31 '07 #2
Another examples are ....
1)
SUBSTR(DIGITS(M ONTH(CURRENT TIMESTAMP)),9,2 )
||'/'||SUBSTR(DIGIT S(YEAR(CURRENT TIMESTAMP)),7,4 )

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

3)
SUBSTR(REPLACE( CHAR(DATE(CURRE NT 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(M ONTH(CURRENT TIMESTAMP)),9,2 )
||'/'||SUBSTR(DIGIT S(YEAR(CURRENT TIMESTAMP)),7,4 )

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

3)
SUBSTR(REPLACE( CHAR(DATE(CURRE NT 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(CU RRENT TIMESTAMP))/100
Result: yyyymm (INTEGER)

2)
SUBSTR(CHAR(CUR RENT 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
60170
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 29-03-2005. How do I get it like that? Thanks, Bob
4
5400
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 calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
1
3122
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" "ddMMyyyy" June 1, 2005 "09-07-05" "MM-dd-yy" Sept 7, 2005 Is there any functions to convert?
1
2213
by: h_ghanaty | last post by:
how i can convert gregorian date to jalaly(Iran date) with vb.net
1
4907
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
4549
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 = Math.Floor(JD+0.5); double W = Math.Floor((Z - 1867216.25)/36524.25); double X = Math.Floor(W/4);
4
15432
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 converts Dates into serial numbers, but I can't figure out how to do it with VB.Net. Please help, thanks.
2
21155
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. When the dates are imported they are in the format dd/mm/yyyy. However on the reports the dates are in the in the format dd/mmm/yyyy. I now need to allow the fields to accept an asterix (*) as a prefix to the date to show dates that have not...
3
2848
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 Source=D:\Netroot\WebApp\testprograms\Shuttle_Service\Attachment\BusRequest.xls;Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;" set objRS = server.createObject("ADODB.recordset") SQL = "SELECT * from " objRS.Open SQL,objConnEx, 1
1
9814
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
9961
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
10785
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...
0
9603
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
7991
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
5825
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...
0
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4644
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
2
4249
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3253
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.