473,397 Members | 2,099 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,397 software developers and data experts.

forming a string with dateparts

I want to create a string using the week number and year of a date.
For instance, if i have a date of 1/3/2007, which would be week 1 of
2007, i want to create a string that says 'Wk1-200707'.
i know it's basically 'WK' + CAST(DATEPART(WK,'1/3/2007') AS VARCHAR)
+ '-' +CAST(DATEPART(YEAR,'1/3/2007') AS VARCHAR) but it's not quite
working for me. Any idea of what I'm missing?
Thanks in advance.
Richard Garth

Aug 30 '07 #1
2 5513
On Aug 30, 8:31 am, rgintexas <rgarth...@yahoo.comwrote:
I want to create a string using the week number and year of a date.
For instance, if i have a date of 1/3/2007, which would be week 1 of
2007, i want to create a string that says 'Wk1-200707'.
i know it's basically 'WK' + CAST(DATEPART(WK,'1/3/2007') AS VARCHAR)
+ '-' +CAST(DATEPART(YEAR,'1/3/2007') AS VARCHAR) but it's not quite
working for me. Any idea of what I'm missing?
Besides using the date in the YYYYMMDD format, no.
Works perfectly for me... What's the problem?

P

Aug 30 '07 #2
You might get different week values than you expect if DATEFORMAT is set to
DMY instead of MDY. As Piero alluded, specifying date literals in the ISO
YYYYMMDD format will ensure the date is interpreted correctly regardless of
DATEFORMAT settings.

Another possibility is that DATEFIRST is set to an unusual value like 2 or 3
(Tuesday or Wednesday) instead of a common value like 7 or 1 (Sunday or
Monday).

--
Hope this helps.

Dan Guzman
SQL Server MVP

"rgintexas" <rg*******@yahoo.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
>I want to create a string using the week number and year of a date.
For instance, if i have a date of 1/3/2007, which would be week 1 of
2007, i want to create a string that says 'Wk1-200707'.
i know it's basically 'WK' + CAST(DATEPART(WK,'1/3/2007') AS VARCHAR)
+ '-' +CAST(DATEPART(YEAR,'1/3/2007') AS VARCHAR) but it's not quite
working for me. Any idea of what I'm missing?
Thanks in advance.
Richard Garth

Sep 3 '07 #3

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

Similar topics

6
by: LRW | last post by:
Because I've had recipients of our newsletter tell us they can't (or won't) receive HTML e-mail, I found out how to make an e-mail that sends both HTML and a plaintext version in a multipart...
3
by: pramod | last post by:
Two differenet applications (running on different OS, different compilers) are communicating thru protocol consisting of functions and arguments. Communication link can be TCP/IP, or serial port....
6
by: juli | last post by:
Hello dear Cor or anyone around!:) This didn't help me(convert) : I have 3 strings in an array : str='11/02/04' ,str='11:23:00" and str=AM. How do I convert str+str+str to a proper datetime...
2
by: MrBiggles | last post by:
Here's something I've been wondering. Do most of you use single or double quotes as a string encapsultor? ex: $s = "This is a string, I can embed ' with no prob"; vs. $s = 'This is a string, I...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
3
by: monomaniac21 | last post by:
hi i have a time string of the form: 2007-05-30 11:46:34 i would like to format this to 30/5/2007, how can i do this? thanks
0
by: sam.barker0 | last post by:
Hi, How can I convert a unsigned char array1 which holds the ipaddress, into a string I am using a char array to insert the '.' between the bytes. I am using a char array because then I can...
5
by: sam.barker0 | last post by:
Hi, How can I convert an unsigned char array containing IPV6 address into a string Eg if arrray contains 20 01 05 03 a8 3e 00 00 00 00 00 00 00 02 00 30 Then the address is Addr:...
11
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database...
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?
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
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,...
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
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
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...

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.