Why I see this page is in wrong month, it should init to show August instead of September , I am from cambodia
http://react-day-picker.js.org/examples/months-initial
From MDN docs:
The argument month is 0-based. This means that January = 0 and December = 11.
var startOfYear = new Date(2017,0)
console.log(startOfYear.toLocaleString())
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
I've been looking around your site for a couple of minutes, and I noticed that the month number is capped at 11 (so December equals 11). That must be because of common code basics, where the first item of an array starts with an index of 0 (= January). Your timezone has nothing to do with the site so don't worry ! (tested from France)
Related
I need to return the year (number) for the previous month. Like 15-Jan-2023, returns 2022.
Simple but I could not find any related solution.
So far I´m using -31 days but this is not as good as February I need to take care and adjust.
< year(getdate()-32)
SELECT DATEPART(YEAR,DATEADD(MONTH,-1,GETDATE()))
example:
SELECT DATEPART(YEAR,DATEADD(MONTH,-1,'15-JAN-2023'))
returns 2022
I'm having a Report where I need to display the dates of last 7 days.
As shown below
Sun, Mon etc... are hard coded and the Dates are written in Expression
For example,
If today is Wednesday I need to show the Dates till last Tuesday.
If it is Thursday I need to show the Dates till last Wednesday.
How to retrieve the dates information and display below the corresponding days.
To get last seven days date you can do something like below in each expression,
To get Days in Header
=WeekdayName(weekday(Parameters!TodaysDate.Value)) --Tuesday
=WeekdayName(weekday(DateAdd("d",1,Parameters!TodaysDate.Value))) --Wedneday
Same for others too... Just by increment/decrement by 1.
To get Days Date in Data
=Format(Parameters!TodaysDate.Value,"dd-MMM-yyyy")
=Format(DateAdd("d", 1, Parameters!TodaysDate.Value),"dd-MMM-yyyy")
Same for others too... Just by increment/decrement by 1.
Here TodaysDate would be parameter date or Now() Date.
I have given demo of incremental one, you can change it as per your condition. I think you need to use decrement here. So Instead of 1 you need to use -1.
This will give you output like below,
Disclaimer: I am just looking for a logic not code
John discovered a strange island called Rasa. The years and weeks on the island are weird. Digging deeper into the island's calendar, he found out that it is similar to rest-of-the-world's (ROW) calendar but the island calendar's Year starts on 1st week of February's calendar. John is asking you to help him solve the problem of converting ROW's calendar into Island's calendar. Here is the question.
You are given a date (today's date). You have to determine the Island week's number. The catch here is that the Island year starts from 1st week of February and every Island's week starts from Sunday and ends on a Saturday. Write a SQL statement in SQL Server to achieve this. Use SQL Server functions and devise a logic.
Input parameter: Any date.
Output parameter: Week No in Rasa Calendar.
Here is an example:
Date: 5th May 2015 --
Week No in ROW Calendar:19
Week No in Rasa's Calendar:14
Date: Jan 1 2017:
Week No in ROW Calendar:1
Week No in Rasa's Calendar:49
My question: can this be achieved in SQL Server?
My homework: I tried a couple of ways to solve the problem.
Approach #1:
Step 1: Calculate the total no of days between today and Feb 1.
Step 2: Divide it by 7 and add 1 to the result.
Later found out that this approach will not work if Feb 1 is on any day other than Sunday.
Eg: 1st Feb is on Wednesday. 5th Feb will be on Monday
So, 1st Feb is on Rasa's week 1, and 5th Feb is on Rasa's week no 2. According to my approach 1st and 5th feb are on week 1 which is incorrect.
Approach #2:
I thought removing 5 weeks of Jan from ROW's calendar should work
select
case
when f.RasaWeek = -4 then 48
when f.RasaWeek = -3 then 49
when f.RasaWeek = -2 then 50
when f.RasaWeek = -1 then 51
when f.RasaWeek = 0 then 52
else
f.RasaWeek
end as Rasa_week,
f.year, f.month, f.date
from
(select
datepart(wk, date) - 5 as RasaWeek, *
from
<datetable>
where
Year(date) in (2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018)) as f
Info: I tested this on a <datetable> but this code will break if there is a 53rd week. Notice that I was not able to take care of the 53rd week.
Any inputs to solve this problem are welcome.
With dates, it's almost always easier to make a calendar table and store the data you care about rather than trying to do anything beyond basic date arithmetic. Use SQL's strengths: storing and retrieving data.
In this case, what you care about are all of the first Sundays in February. If you store these dates in a table, the solution is:
RETURN
SELECT TOP 1
DATEDIFF(day,[date],#input_date) / 7
FROM IslandCalendarStartDates
WHERE [date] <= #input
ORDER BY [date] DESC
This way you don't need to worry about leap years or 53-weeks, or any of the edge cases. Just count the days from the most recent first Sunday in February and divide by 7. If you need to change the solution to accommodate a different start date, you only change the data, not the code.
Im developing a simple application that show the daily budget until the next payment. For that I'm using momentJS.
The problem is that the logic in my application is wrong. Im, first finding what day is it, then I find the first day of the this month (date(1)), then I sum 1 month and 14 days. But whenever its the next month (as right now -02/12), it will, of course tell me that the next 15th is in February.
Long story short, how do I find the next 15th using moment?
Here is my application:
$scope.nextDate = moment().date(1).add(1, "months").add(14,"days"); //calculate when is the next 15th
$scope.difference = Math.floor(moment.duration($scope.nextDate.diff($scope.today)).asDays());
Thanks in advance!
Use a simple condition in the add method when calculating the nextDate.
$scope.nextDate = moment().date(1).add((moment().date() > 14 ? 1 : 0), "months").add(14,"days");
This will either add 0 or 1 months to your calculation based on the condition if current date is larger than 14 (modify to 15 if you want to count "next" 15th as today when it's actually 15th)
In Russia the first day of the week is Monday. In the United States - Sunday. On Linux nl_langinfo(_NL_TIME_FIRST_WEEKDAY) return 0 for Sun or 1 for Mon. How do I get too in MacOS X with c-code?
I haven't tried it myself, but from skimming the docs, you can get a CFLocale instance (reference) and get it's CFCalendar instance using:
CFLocaleGetValue(locale, kCFLocaleCalendar)
And get the first day of the week from the CFCalendar instance using CFCalendarGetFirstWeekday() (reference).
My guess would be to use CFDateRef and CFLocaleRef opaque types and associated CFDate* and CFLocale* functions from CoreFoundation framework.
UPDATE
After some digging I found the function you need. It appears that you have to use CFCalendar for this. From apple's documentation:
CFCalendarGetFirstWeekday
Returns the index of first weekday for a specified calendar.
CFIndex CFCalendarGetFirstWeekday (
CFCalendarRef calendar
);
Parameters
calendar
The calendar to examine.
Return Value
The index of the first weekday of the specified calendar.