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

Return a string representing the day of the week

Hi All,

New to the forum and new to T-SQL

I'm trying to add a column to the results of query that shows a text string representing the day of the week.

Expand|Select|Wrap|Line Numbers
  1. Select Activity.StartDateTime as DAY
...returns the full date and time. I just want the day of the week.

I know it's possible to return an integer which represent the day of the week, and I know there's a way to specify which day of the week you want to call the first. Typically in the US the first day of the week is Sunday I think, but here in the UK it's Monday.

Thing is, I don't just need an integer, I need a string that represents the abbreviated form of the actual name of the day.

eg

MON = Monday
TUE = Tuesday

etc etc

Can anyone help please? Don't know where to start.

Bob
Aug 31 '06 #1
5 23841
After much hunting around online I've found the DATENAME function which apparently when used with "weekday" as per the example below returns a string like "Sunday", "Monday" or whatever based on the day of the week that correlates to the date

Expand|Select|Wrap|Line Numbers
  1. DATENAME(weekday, Activity.StartDateTime)
However, now that I'm at home (not work where I have enterprise manager) I can't test this. Ideally I want to return the first three letters of the string and capitalize them. I'm guessing for the first three letters I could adapt the code above thus:
Expand|Select|Wrap|Line Numbers
  1. SELECT LEFT(DATENAME(weekday, Activity.StartDateTime),3) As DAY
Anyone any ideas firstly if this will work and secondly if there's an equivalent to excel/vba's UPPERCASE to capitalize the string?

Any help would be appreciated. :)

Bob
Aug 31 '06 #2
Maybe someone could paste...

SELECT LEFT(DATENAME(weekday, GETDATE()),3) As DAY

...into Query Analyzer and tell me what they get (should be the first three letters of the name of the current day of the week)
Aug 31 '06 #3
For anyone else wanting to do the same - it does work!

Thanks for all your help everyone!
Sep 1 '06 #4
Thanks - this was something I needed, but I wasn't aware that it existed!
Sep 30 '10 #5
ck9663
2,878 Expert 2GB
As always, these kinds of things is always recommended to be done on your front-end. Unless of course this is some sort of data extraction.

In any case, glad it worked.

Happy Coding!!!

~~ CK
Oct 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Terry Hancock | last post by:
What do you do when a date or time is incompletely specified? ISTM, that as it is, there is no formal way to store this --- you have to guess, and there's no way to indicate that the guess is...
7
by: .Net Sports | last post by:
Before processing my data in a datagrid, I need to parse the day of the week (which will be my 'rqsday' variable) from a string that comes over on a querystring: string rqs =...
2
by: Agnes | last post by:
Does .net provide any function for such purpose ? e.g today is 21-10-2004, the week is 43, now I want to get the DATE with (week 42, Monday) Thanks alot
1
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the...
13
by: Angus | last post by:
Hello I have a stream of bytes - unsigned char*. But the 'string' may contain embedded nulls. So not like a traditional c string terminated with a null. I need to calculate the length of...
4
by: Christopher Benson-Manica | last post by:
In a thread from substantially earlier this week, Harald van D?k <truedfx@gmail.comwrote: Being rather pendantic, I decided to try to verify whether this was true. I would appreciate...
6
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
50
by: Bill Cunningham | last post by:
I have just read atoi() returns no errors. It returns an int though and the value of the int is supposed to be the value of the conversion. It seems to me that right there tells you if there was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
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...
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
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...

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.