I need to identify day, month and year selected in datetimepicker and validate the date - calendar

I need to set up a calendar in datetimepicker with simple rules, day can't be less than 01, day can't be greater than 31, month can't be less than 01, month can't be greater than 12, year can't be less than 0001 and also identify the leap year to set February with 28 or 29 days.

Related

Disable 31st of every month React-native-calender

I am working for fintech app, And Want to disable 31st of every month as the salary doesnt get credited on 31st of any month

SSRS - Add year to month

In my report, i show the sales commission for 3 months from each sales person. I've also added the payout month. For a better overall look, i want to add the year to the payout month.
This is the month in my SQL-Query :
,[Monat] = convert(varchar(4),Year(Datum)) + right('00' + convert(varchar(2),Month(Datum)),2)
Right now, the expression for my payout month is this:
=MONTHNAME(IIF(RIGHT(Fields!Monat.Value,2)+2>=13,RIGHT(Fields!Monat.Value,2)-12+2,RIGHT(Fields!Monat.Value,2)+2))
The payout is always two months in the future. Commission of december 2020 will be payed in february 2021, january 2021 will be payed in march 2021 and so on.
I want the result to look like this:
Februar 2021,
März 2021
etc.
Is there a way to depict that in the SSRS expression? Thanks in advance.
If you just need to display the month and year from a date field after you have added 2 months to it, then you can just do something like this.
=DATEADD(DateInterval.Month, 2, Fields!Datum.Value)
You can then format the textbox using MMMM yyyy to display it as you want.
Alternatively, you can do it all in a single step but this should be avoided if possible as you are then losing the date and converting to a string. If you exported to excel for example, you would not be able to do anything with the cell as it would just be a string.
If you really have to do this in all in a single expression then you can use
=FORMAT(DATEADD(DateInterval.Month, 2, Fields!Datum.Value), "MMMM yyyy")

Extended calendar which runs on 1st business day of 3rd of every month in autosys

I need to create extended calendar which will run on 1st business day of 3rd week of every month.
Mon to Fri are considered as working day and no holiday calendar included.
Sample dates for year 2018 :
16th Jan, 13th Feb, 13th Mar, 17th Apr, 15th May, 12th Jun, 17th Jul, 14th Aug, 11th Sep, 16th Oct, 13th Nov, 11th Dec
Currently I am using standard calendar for this but wants to change it to extended calendar to avoid manual inserts for every year.
#Manvi
not very confident of the exact condition and this would be a partial answer.
as for now i can think of
WEEK#03|WEEK#07|WEEK#11|WEEK#15|WEEK#20|WEEK#24|WEEK#28|WEEK#33|WEEK#37|WEEK#42|WEEK#46|WEEK#50
This would give you all the 3rd week of the the months and then hereon need to exclude the rest of the days.
You can refer this link for condition keywords.
Also, you can use below to include multiple keywords for desired output.
OR condition as "|"
NOT as "NOT"
Hope this helps. Good luck.
Will update incase i do find the solution.
Edits:
The first working day would definitely be a Monday and the previous day has to be 2nd Sunday.
Consider a calender as below
extended_calendar: Cal_name
description: 1st day of the 3rd week
workday: mo,tu,we,th,fr
non_workday:
holiday:
holcal:
cyccal:
adjust: +1
condition: sun#2
Sun#2 would consider the 2nd sunday of all months and the next day would mark the start of the 3rd week.
To consider the next day of the 2nd sunday adjust: +1 defined.
If you are looking for the 2nd day of the 3rd week. Defined adjust to +2.

Alexa slot AMAZON.DATE handle dates without years

I am building an Alexa skill and using AMAZON.DATE slot type to get a date.
My problem is that when a user says a date without a year, Alexa processes it and returns the date string with a future date.
Example - Today is 2017-09-20, User asks Alexa about date 'Sixth June', Alexa returns 2018-06-06.
I want to use the closest past date instead of closest future dates, for the case when the user doesn't specify a year in the utterance. If the user specifies a year, I don't want to change the date year.
I can't handle this on AWS Lambda using Python, as Alexa sends the complete date string, no matter if the user provides the year or not, in the JSON body.
I don't know if it is even possible to handle such user inputs with Alexa. Is there something I can do about the AMAZON.DATE slot or some other way to handle such user utterances?
You cannot do that with built-in date slot,
Utterances that map to a specific date (such as “today”, or “november twenty-fifth”) convert to a complete date: 2015-11-25. Note that this defaults to dates on or after the current date.
Source :- https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/built-in-intent-ref/slot-type-reference#date
one logic you can try it out is to do a custom logic. Take the difference between todays date and next year same date of user input. If the difference of months between those is greater than 6 months then the nearest would be future date. If difference is less that 6 months then past date. Say user gives an input July 25th (on 2017 ) and todays date is August 25th 2017. Now you can add 1 year to July 25th then you will get July 25th 2018. Difference between July 25th 2018 and August 25th 2017 is greater than 6 months so the date you want is past date, which is July 25th 2017 and vice versa. For more accuracy you can count in days instead of months
After converting Alexa's slot input date string to a js date object, (probably with amazon-date-parser) the below could work
if (dateobj > new Date()) {
var currentMonth = new Date().getMonth()
var dateMonth = dateobj.getMonth()
var offset = dateMonth > currentMonth ? 1 : 0 // if current month is to be set with past year use >=
dateobj.setFullYear(new Date().getFullYear() - offset);
}

Implentation of a date in SQL Server

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.

Resources