logo
down
shadow

How do I find week number of a date according to DATEFIRST


How do I find week number of a date according to DATEFIRST

By : Gopal Barman
Date : November 18 2020, 03:49 PM
help you fix your problem How to find week number of a date if start day is Tuesday and end day is Monday? , Set your first day to Tuesday
code :
SET DATEFIRST 2
DECLARE @FROMDATE DATE='31-Dec-2014'

SELECT CAST(UPPER(DATENAME(YEAR, @FROMDATE)) AS VARCHAR(20))
+'_'+CAST(UPPER(DATENAME(MONTH, @FROMDATE)) AS VARCHAR(20))
+'_WEEK_NO_'+REPLACE(CAST((DAY(@FROMDATE) 
+ (DATEPART(DW, DATEADD (MONTH, DATEDIFF (MONTH, 0, @FROMDATE), 0))-1) -1)/7  AS VARCHAR(10)),'0','1')
SET DATEFIRST 2

DECLARE @FROMDATE DATE='12-JAN-2015'
DECLARE @ALLDATE DATE=DATEADD(month, DATEDIFF(month, 0, @FROMDATE), 0)
DECLARE @FIRSTDATE DATE


; WITH  CTE as
 (
     SELECT 1 RNO,CAST(@ALLDATE AS DATE) as DATES 
     UNION ALL
     SELECT RNO+1, DATEADD(DAY,1,DATES )
     FROM    CTE
     WHERE   DATES < DATEADD(MONTH,1,@ALLDATE)
 )
 SELECT TOP 1 @FIRSTDATE =   DATES 
 FROM    CTE 
 WHERE DATEPART(W,DATES)=1


SELECT CAST(UPPER(DATENAME(YEAR, @FROMDATE)) AS VARCHAR(20))
+'_'+CAST(UPPER(DATENAME(MONTH, @FROMDATE)) AS VARCHAR(20))
+'_WEEK_NO_'+CAST((DATEDIFF(DAY,@FIRSTDATE,@FROMDATE)/7)+1  AS VARCHAR(10))


Share : facebook icon twitter icon
Find start-end date of a week from week number

Find start-end date of a week from week number


By : Иван Прокопиев
Date : March 29 2020, 07:55 AM
With these it helps You can use Calendar for this,
code :
 Calendar cal = Calendar.getInstance();
 cal.set(Calendar.WEEK_OF_YEAR, week);
 Date yourDate = cal.getTime();

 cal.setTime(yourDate);//Set specific Date of which start and end you want

 Date start,end;

 cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
 start = cal.getTime();//Date of Monday of current week

 cal.add(Calendar.DATE, 6);//Add 6 days to get Sunday of next week
 cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
 end = cal.getTime();//Date of Sunday of current week
 System.out.println(start +" - "+ end);
SQL Week of Month without DATEFIRST

SQL Week of Month without DATEFIRST


By : Sam
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Update: based on asker's comment that he cannot use the DATEFIRST approach I am updating answer.
Note:
code :
SELECT  [WkNo]=
 ISNULL(DATEPART(week,
                      case 
                         when Year(dt.DT)>YEAR(dateadd(dd,-1,dt.DT)) 
                         then null  
                         else dateadd(dd,-1,dt.DT) 
                      end
                 ),1) 
    SET DATEFIRST 1
 -- [WkNo]=Week number                                
    [WkNo]      = DATEPART(week,dt.DT),
How to find the date number given the Year, month, day of the week and the week it falls on in ruby

How to find the date number given the Year, month, day of the week and the week it falls on in ruby


By : quickpoint
Date : March 29 2020, 07:55 AM
hop of those help? So i'm new to ruby and not to familiar with the syntax of the Date gem, but is there a way to find the date of a moving holiday like fathers day?
code :
class MovingHoliday < Holiday
    def initialize (name, month, day_of_week, week, year=2016)
        @name = name
        @month = month
        @day_of_week = day_of_week
        @week = week
        @year = year
        @my_date = Date.new(year, month, 1)
        @my_date += 1 while !my_date.send("#{day_of_week}?")
        @my_date += (7 * (week - 1))
    end  
end
How to get start week date and end week date from a week number in Google Scripts

How to get start week date and end week date from a week number in Google Scripts


By : Dwi C Taniel
Date : March 29 2020, 07:55 AM
With these it helps If this is running from a trigger at the end of the week, it's easier to just do some basic math and subtract 7 from the current date, rather than doing the extra math with week numbers.
code :
function setDates() {
  var timezone = Session.getScriptTimeZone();

  var tempStartDate = new Date();
  tempStartDate.setDate(tempStartDate.getDate() - 7); //subtract 7 to get date from 1 week ago
  var startDate = Utilities.formatDate(tempStartDate, timezone, 'dd.MM.yyyy');
  Logger.log(startDate);

  var tempEndDate = new Date();
  var endDate = Utilities.formatDate(tempEndDate, timezone, 'dd.MM.yyyy');
  Logger.log(endDate);

  var dateRange = startDate + ' - ' + endDate;
  Logger.log(dateRange);
}
startDate = 25.04.2019
endDate = 02.05.2019
dateRange = 25.04.2019 - 02.05.2019
DATEPART: specifying first day of week when SET DATEFIRST cannot be used

DATEPART: specifying first day of week when SET DATEFIRST cannot be used


By : user3240938
Date : March 29 2020, 07:55 AM
hop of those help? You can try something along this using @@DATEFIRST. This is a system variable you can use without any declaring or setting in inline/ad-hoc queries:
--This is a Sunday
code :
DECLARE @OneSunday DATE='20190929';
SET LANGUAGE ENGLISH;
SELECT DATEPART(week, @OneSunday); --<-- returns 40
SELECT @@DATEFIRST;                --<-- returns 7  

SET LANGUAGE GERMAN;
SELECT DATEPART(week, @OneSunday); --<-- returns 39
SELECT @@DATEFIRST;                --<-- returns 1
SET LANGUAGE ENGLISH;
SELECT DATEPART(week, DATEADD(DAY,(@@DATEFIRST % 7),@OneSunday));

SET LANGUAGE GERMAN;
SELECT DATEPART(week, DATEADD(DAY,(@@DATEFIRST % 7),@OneSunday));
Related Posts Related Posts :
  • Why does C# also not allow empty conditions in while loops?
  • Unable to get a block of code into my regex match groups
  • What is difference between dbcontext.Add and dbcontext.AddObject
  • How do I update the file version number of C# DLL without recompiling?
  • Value for html control always null
  • HttpClient hangs when timeout is setting (Windows Phone)
  • Handle Multiple Form tag in asp.net page?
  • create word document with html content in c#
  • Confusion about Find And Replace
  • Format sms messages in Clickatell
  • Automated Function Overload
  • String to date in MS Access SQL statement gives type mismatch error
  • ShowDialog exiting on certain events
  • Is there a try Convert.ToInt32... avoiding exceptions
  • How to move wpf application into minimize tray at Window Start-up C#?
  • How to change display format of long variable?
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org