I want to convert date to week consider saturday is first day of week and friday is end of week. for input is orderdate and output should be week. example orderdate 11.04.15 to 17.04.15 week should be 16. orderdate 18.04.15 week should change to 17.
Order DateWeek 11-Apr-201516 12-Apr-201516 13-Apr-201516 14-Apr-201516 15-Apr-201516 16-Apr-201516 17-Apr-201516
I am working with Week Numbers and was wondering if there is a way to display Week 1 as 01.
The problem that I am having is that when I list the weeks from Week 1 to Week 12 is that the sorting is 1, 10, 11, 12, 2, 3 and I would like to get it to look like 01, 02, 03....09, 10.
Any easier way to do what I am trying, without having a table with all the dates and week numbers.
Scenario: Week number of a DateTime Field where the year does not start on January 01<sup>st</sup> but April 1<sup>st</sup> to 31 Mach.
Issue: A week always starts on a Monday so if the 1<sup>st</sup> is on Tuesday, the first week is Tuesday – Sunday, if the 1<sup>st</sup> April is on Friday, the 1<sup>st</sup> week is Friday – Sunday and 7 day periods from there.
CREATE TABLE [dbo].[DailyCanx]( [ID] [int] IDENTITY(1,1) NOT NULL, [DateCancelled] [datetime] NULL ) ON [PRIMARY]
[code]....
I could create a table with all the start date and end dates of all the week numbers but I think there must be a better way. using SQL Server 2008 R2.
SQL express 2012. I am trying to case in the where part and having a syntax errors - This is what i am trying to do:
select all the days in week number x including last year if necessary... so if the year start not at the beginning of the week then look in last year as well ( for the same week number of this year and last week nu of last year)
declare @yyyy int = 2014,-- THE YEAR @mm int = 1,-- THE MONTH @week1No int = 1,-- THE WEEK NUMBER IN THE YEAR @week2No int = 37-- THE last WEEK NUMBER IN last YEAR select count(tblDay.start)-- tblDay.start IS smallDatetime
I am trying to case in the where part and having a syntax errors - this is what i am trying to do:
Select all the days in week number x including last year if necessary... so if the year start not at the beginning of the week then look in last year as well ( for the same week number of this year and last week nu of last year)
declare @yyyy int = 2014,-- THE YEAR @mm int = 1,-- THE MONTH @week1No int = 1,-- THE WEEK NUMBER IN THE YEAR @week2No int = 37-- THE last WEEK NUMBER IN last YEAR select count(tblDay.start)-- tblDay.start IS smallDatetime
I need to write a user defined function that will return the date of the first day of a week when provided with the week number. I had an idea of using a while loop with that will keep adding 1 day from January 1st until the week number (found via the DATEPART function) is equal to the supplied week number. Not sure if this is the best way though - any ideas?
I'm wanting to see if there is a simpler way to accomplish the retrival of the first day of the week Date. What I currently have is:
CASE WHEN DATEPART(DW, GETDATE()) = 1 THEN DATEADD([D], - 7, GETDATE()) WHEN DATEPART(DW, GETDATE()) = 2 THEN DATEADD([D], - 8, GETDATE()) WHEN DATEPART(DW, GETDATE()) = 3 THEN DATEADD([D], - 9, GETDATE()) WHEN DATEPART(DW, GETDATE()) = 4 THEN DATEADD([D], - 10, GETDATE()) WHEN DATEPART(DW, GETDATE()) = 5 THEN DATEADD([D], - 11, GETDATE()) WHEN DATEPART(DW, GETDATE()) = 6 THEN DATEADD([D], - 12, GETDATE()) WHEN DATEPART(DW, GETDATE()) = 7 THEN DATEADD([D], - 13, GETDATE()) END AS StartWeek1
I'm trying to figure if there might be an easier way to code this. Thanks.
Hey, Im pretty sure this is possible, but let me know if it isnt.I have a table of dates in the format "DD/MM/YYYY", is there a way of converting it to output the day of the week? for example 16/11/2007 would display Friday insted.Thanks in advance John
I need SQL to determine what the date range for the previous week was, ie Start date 11/11/01 for Last Sunday through 11/17/01 the following Saturday. The results will populate a drop down box for user queries. Thanx.
Hi Guys, Can anyone please let me know How to find the first day of the week, if I know the weekno and the year. For ex: If I know the week no is 22 and Year is 2003 then I should find a way to output the date. which is the first day (monday) of that week for the above query the date will be eg:26/06/2003
I really appreciate your Help
Thanks:confused: Find the Date if I know the week and year
What i have tried has'nt even been close to a solution. UPDATE dbo.t_Work_Hours SET WeekEnding = DATETIME ( ??? , StartTime) . I have no idea where to go!
How do i get only the records for everything with only the dates from last week (monday-friday)? I want to have this run every week for the previous week. Here's my stored procudure. Right now i have this to run for the day before, but now i need it for the week before. So its a range. Please Help. Thanks!
Code Snippet CREATE PROCEDURE [dbo].[Testing_Out_Of_Stock_SKUS_WEEKLY] (@Classification varchar(50)) AS BEGIN SELECT RC_STAT.dbo.Brand_Dimension.Report_Level, RC_STAT.dbo.Brand_Dimension.[Cat vs Dog], RC_STAT.dbo.Brand_Dimension.Item_Merged, Qry_Sales_Group.Region_Key, Qry_Sales_Group.Region, Qry_Out_Of_Stock.product_structure_level, Qry_Out_Of_Stock.product_entity_code, Qry_Out_Of_Stock.cycle_day, Qry_Out_Of_Stock.customer_code, Qry_Out_Of_Stock.description, Qry_Sales_Group.Code, Qry_Sales_Group.SR_Name, Qry_Sales_Group.Name AS Territory_Name, Qry_Out_Of_Stock.Store_Name, Qry_Out_Of_Stock.time_log, Qry_Out_Of_Stock.out_of_stock, Period_Code FROM RC_STAT.dbo.Brand_Dimension INNER JOIN dbo.Qry_Out_Of_Stock ON RC_STAT.dbo.Brand_Dimension.Item_Key = dbo.Qry_Out_Of_Stock.product_entity_code COLLATE SQL_Latin1_General_CP1_CI_AS INNER JOIN dbo.Qry_Sales_Group ON dbo.Qry_Out_Of_Stock.sales_person_code = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code COLLATE Latin1_General_CI_AS Where Classification=@Classification DateDiff(dd,0,dbo.Qry_Out_Of_Stock.time_log) = case when Datepart(Weekday, Getdate()) = 2 then datediff(dd,0,GetDate()) - 3 else datediff(dd,0,GetDate()) - 1 end
I don't know if this can be done, but hopefully one of the experts in this forum cna help me out.
I have a TimeOff table which contains 5 fields: timeoffID, employeename, startdate, enddate, and timofftype. I need to create a report which shows how many people take sick day (one of the timeofftypes) on each week day (i.e. Monday, Tuesday, Wednesday, and etc.) The problem is that I don't know how to convert the date range (from startdate to enddate) into indvidual week day for each timeoff record.
For example, on the table,
TimeoffID employeename startdate enddate timeofftype 1 Andy 11/02/2006 11/03/2006 Sick Day 2 Bill 11/03/2006 11/03/2006 Sick Day