Check if day is valid for selected month Django forms - django

I have a form where the user types a day (number between 1 and 31) and then selects a month from a list and then types a year.
The problem is that when a date such as (31 February) will throw the following error:
day is out of range for month
Is there a way I can check if the day is valid for that month (and year if it is a leap year) in the form?

If you use django Forms check SelectDateWidget
btw, why don't you want to catch such errors and show above your form in other words (if you allow to choose and submit 31 and 'February')?

Related

Django group by jalali week number

I'm working on django api using a PostgreSQL database. The model has a date field representing a travel time (in jalali format) and an integer field representing number of passengers for that travel.
I'm using django_jalali to handle jalali date queries.
from django_jalali.db import models as jmodels
class TravelReport( models.Model ):
travel_date = jmodels.jDateField(verbose_name="تاریخ سفر")
passengers = models.IntegerField()
I want to aggregate sum of passengers for each week number in a jalali year. This is the query I'm using:
queryset= TravelReport.objects.annotate(week=F("travel_date__week")).values("week").annotate(total_passengers=Sum("passengers"))
Here is my problem: Django lookup __week is returning Georgian week number not jalali week number. For example week number for a travel date with jdatetime.date(1390, 5, 12) should be 19 but my query is returning 31.
What are my options to fix this?
Ok. Lets work out options:
override the lookup method to work using the jalali calender format.
convert your dates to gregorian format and store in another field, and call a function taht takes as input jalali format date, and sends the reciprocating gregorian format date to the lookup field.
Keep the number of passengers for a week stored in a separate field, with key as jalali calender weekname and value will be the number of passengers for that week.

Multiple conditions to see users

I need to go through two conditions here, looking for Employees who have passed with the below conditions:
If 'Passed' from 1 week of enrolled date
And the user is among the TOP 10 of overall performance percent or passed all quizzes in the past 12 months
Capture 2.PNG
I have created a new column to give me the 7th day from the enrolled date which will show me if the user completed it before this date and want only those users who completed it between the 7th day of enrolled date.
7th Day of Enrolled Date = [Merged] + 7
Now I need to know who are those users who did it...may be another column with Yes or No and filter only those which have 'Yes'??
Can someone please advise on how I can achieve this?
Thank you!

AWS Quicksight: Display week as a number, grouped by month and not year

I need to display Week as number in AWS QuickSight.I understand, we can do this to get the week numbers: In the field wells, click the format option for the date field and on the left side-panel, enter 'w' in the Custom format field.
The issue is this gives the week number in the year. How do I get week number per month?
You can use calculated fields to calculate it.
It depends how you define "week of month". In a simple case, if you define first 7 days of a month as "week 1", the second 7 days as "week 2", etc, use this formula:
dateDiff(truncDate('MM', mydate), mydate, 'WK') + 1
I do a date-diff (in weeks) between first day of month (truncDate) to input-ed date.
Result:

Nintex Conditional Rules According to a Choice Field

in my list i have these cloumns:
1- a choice drop-down List (Item1, Item2,.....)
2- Date-and-Time filed
the List date and time field need to be compared with the current date and time according to the choice from the drop-down list
for Item1, the entered DATE should be >= 2 days from current date
for Item 2, the entered TIME should be >= 2 hours from current time
for any other item, no need for any validation

how to get the next day date in informaitca

I have a date field coming form source paid_date and i want it to convert as
trunc(next_day(sysdate-1,'MON')).. I need to get the NEXT_DAY here and the filed data type is date-time.
Please share your inputs.
Unfortunately, as of now, there is no NEXT_DAY equivalent in Informatica. So you have to calculate it like this in expression.
TRUNC(
ADD_TO_DATE(
SYSDATE,
'DD',
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7
)
)
Explanation:
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7 - Calculates the number of days till next Monday.
ADD_TO_DATE(SYSDATE,'DD',...) - Adds the above no. of days to the input date
In this case you can use Add_To_Date function. Using this function you can get your exact date or month or year.
Formats of defining date,
Date – DD, DDD, DY and DAY
Month – MM, MON and MONTH
Year – YY, YYY and YYYY
Hour – HH, HH12 and HH24
Minute – MI
Seconds - SS
Syntax : ADD_TO_DATE (date_column, format, value)
Example: ADD_TO_DATE (Date, ‘DD’, 10)
Result:
10/01/2016 - 20/01/2016
As the format is provided as ‘DD’ and value as 10, the dates are displayed by increasing 10 days. This logics stands for date, month, year, minute, hour or seconds whatever defined in the syntax. To decrease the date value just add negative number (-10).
For you to get next day, just define
ADD_TO_DATE (Your column, ‘DD’, 1).
For more details on informatica just visit my blog,
http://etlinfromatica.wordpress.com/