[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp: label.text to week of year?

Posted on 2009-12-24
4
Medium Priority
?
320 Views
Last Modified: 2013-11-07
I need to get the week of year into SQL.
Everything I have tried generates runtime or compile errors.
How can I do this:

I have asp:

Label2.Text = string of a date of the year


SQL: " ... DATEPART(wk, CONVERT(datetime,@Label,101) ) "

<SelectParameters>
               <asp:ControlParameter Name="Label"  ControlID="Label2"  PropertyName="Text" />
               </SelectParameters>
0
Comment
Question by:pillmill
  • 2
4 Comments
 
LVL 4

Expert Comment

by:liorfr
ID: 26121043
This one works:
DECLARE @date datetime
SET @date = '20090301'

SELECT CASE WHEN @date NOT BETWEEN DATEADD(day, -DATEPART(dw, (DATEADD(year, DATEDIFF(year, 0, @date) +1, 0))), (DATEADD(year, DATEDIFF(year, 0, @date) +1, 0))) +1 AND DATEADD(year, DATEDIFF(year, 0, @date) +1, 0) -1 THEN DATENAME(week, @date)
ELSE 1 END

Lior
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 26121236
0
 
LVL 6

Expert Comment

by:havj123
ID: 26124028
use this

Dim weekNum As Integer = DatePart(DateInterval.WeekOfYear, Date.Now, Microsoft.VisualBasic.FirstDayOfWeek.Monday)
0
 
LVL 6

Accepted Solution

by:
havj123 earned 2000 total points
ID: 26124031
or in C#

public static int GetWeekNumber(DateTime dtPassed)
{
        CultureInfo ciCurr = CultureInfo.CurrentCulture;
        int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
       return weekNum;
}

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question