Hi All,
I want to add Suffix in dates like nd,st,rd,th to dates like 2,1,3,4 respectively.....
What is the function used in Sql Server and oracle both??
Thanks & Regards
Nitin Sharma
Software Engineer
.Net Technologies
5 8227
Hi,
here is the sample query (sql server) to give suffix to the date
sample code: -
-
DECLARE @Date datetime
-
-- I am using @date variables, you can change it to column name if you are retrieveing data from table
-
set @Date = Getdate()
-
-
SELECT CASE WHEN DAY(@Date) in (1,21,31) THEN convert(varchar,DAY(@Date)) + 'st'
-
WHEN DAY(@Date) IN (2,22) then convert(varchar,DAY(@Date)) + 'nd'
-
WHEN DAY(@Date) IN (3,23) then convert(varchar,DAY(@Date)) + 'rd'
-
ELSE convert(varchar,DAY(@Date)) + 'th ' end +
-
DATENAME(month, @Date) + ', ' + convert(varchar,year(@Date)) as CertificationDate
-
thanks
Hi,
here is the sample query (sql server) to give suffix to the date
sample code: -
-
DECLARE @Date datetime
-
-- I am using @date variables, you can change it to column name if you are retrieveing data from table
-
set @Date = Getdate()
-
-
SELECT CASE WHEN DAY(@Date) in (1,21,31) THEN convert(varchar,DAY(@Date)) + 'st'
-
WHEN DAY(@Date) IN (2,22) then convert(varchar,DAY(@Date)) + 'nd'
-
WHEN DAY(@Date) IN (3,23) then convert(varchar,DAY(@Date)) + 'rd'
-
ELSE convert(varchar,DAY(@Date)) + 'th ' end +
-
DATENAME(month, @Date) + ', ' + convert(varchar,year(@Date)) as CertificationDate
-
thanks
Hi Dear..
Thank you....
I am using the query sent by u...but m having problem in retrrieving the date as like ur query is returning...
I have a date field in the table with datetime as a datatype and i have replaced the Getdate() function with (Select date from tablename)..that is it....
Please tell what all i have to change....
My table name is XYZ
My field name is Date..
Thanks
Nitin
Hi Dear..
Thank you....
I am using the query sent by u...but m having problem in retrrieving the date as like ur query is returning...
I have a date field in the table with datetime as a datatype and i have replaced the Getdate() function with (Select date from tablename)..that is it....
Please tell what all i have to change....
My table name is XYZ
My field name is Date..
Thanks
Nitin
Hi,
what i mean to say is use the query as follows: -
SELECT CASE WHEN DAY(Date) in (1,21,31) THEN convert(varchar,DAY(Date)) + 'st'
-
WHEN DAY(Date) IN (2,22) then convert(varchar,DAY(Date)) + 'nd'
-
WHEN DAY(Date) IN (3,23) then convert(varchar,DAY(Date)) + 'rd'
-
ELSE convert(varchar,DAY(Date)) + 'th ' end +
-
DATENAME(month, Date) + ', ' + convert(varchar,year(Date)) as CertificationDate
-
FROM XYZ
-
thanks
Hi,
what i mean to say is use the query as follows: -
SELECT CASE WHEN DAY(Date) in (1,21,31) THEN convert(varchar,DAY(Date)) + 'st'
-
WHEN DAY(Date) IN (2,22) then convert(varchar,DAY(Date)) + 'nd'
-
WHEN DAY(Date) IN (3,23) then convert(varchar,DAY(Date)) + 'rd'
-
ELSE convert(varchar,DAY(Date)) + 'th ' end +
-
DATENAME(month, Date) + ', ' + convert(varchar,year(Date)) as CertificationDate
-
FROM XYZ
-
thanks
Thanks a lot..My dear..!! It worked..
Also..tell..What if it is not a date and a simple number field more than 30 or 31 ...
Waiting for the reply...!!
Thanks ,
Nitin Sharma
Thanks a lot..My dear..!! It worked..
Also..tell..What if it is not a date and a simple number field more than 30 or 31 ...
Waiting for the reply...!!
Thanks ,
Nitin Sharma
Hi,
sql server treats number 1 as 1900-01-01. (yyyy-mm-dd)
If you given any number then it starts counting from the date above, and convertrs it as another date. like
if you give the date as 0 then it takes 1900-01-01,
if the date is given as 32 then it will be 1900-02-02
for more details do as follows you will come to know exactly what happening
declare @date as datetime
set @date = 1
-- try with different numbers values
select @date as date
thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: p.kosina |
last post by:
Its just for my convienience:
When saving new file in IDLE I HAVE to always manually add suffix .py,
otherwise it is saved without ANY suffix.
Can it be set somewhere?
Thank you
Pavel
|
by: Iain Downie |
last post by:
Dear list,
we are getting a few folk trying to register for our birdwatching surveys
with emails of the form: aname@phonecoop.coop, in other words with a 4
character ending (other examples are...
|
by: Green |
last post by:
Hi,
I have a question that when i surf the internet, i found out that using
..aspx suffix means using asp.net, using .jsp means using javaserver page,
etc. But some don't have any suffix. For...
|
by: Dixie |
last post by:
I am trying to calculate the number of workdays between two dates with
regards to holidays as well. I have used Arvin Meyer's code on the Access
Web, but as I am in Australia and my date format is...
|
by: Hamish M |
last post by:
Hi I am interested in opinions on this topic.
I have heard that a suffix is not a good solution and type casts are
much better
for example.
...
|
by: Denis Jevon |
last post by:
I have a problem which is probably simple to solve but I can't find the answer. In the past I have added pages to sites I have built with names like aboutus.html and when I or anyone else wants to...
|
by: SARAHE |
last post by:
I have a C++ programming problem to extract a suffix such as Jr. or Sr. from a string that may vary each time. We are currently working with one assigned variable but I wanted to know how to code it...
|
by: Cyber dorkz |
last post by:
hello, i've got this problem , as example :
long number = 2000000000
my manual says that you must place a suffix after 2000000000 :
long number = 2000000000L.
suffix L means int must be...
|
by: Weatherman |
last post by:
I've searched for an answer to this and can't find one. I can't view
pages with the PHP suffix. The basic (top) part comes up in my
browser, but the part with the PHP element does not. I've...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
| |