I am using DatePicker and I want to set a calendar date based on other calendar field, if the date of first calendar falls in current month then the date of second calendar should be valid from the date of first calendar (for eg: 1st calendar date is set to 20-06-2021 which is of current month then the second calendar date should allow to add date from 20-06-2021), if the date of first calendar falls in last month then the date of second calendar should be valid from the start date of this month (for eg: 1st calendar is set to 20-05-2021 which is of last month then the second calendar date should allow to add date from 01-06-2021), please give me a solution on how I can resolve this issue.
You can do it by using state suppose you have started your first date picker from 2021-06-20
this.state = {date:"2021-06-20"}
and then when the user changes the date you update your state by
onDateChange={(date) => {this.setState({date: date})}}
now by using this updated state you can start your second date picker by using the current state.
And by assigning it to a variable you can apply any conditional statements that you want.
Related
I have a date column which is the first day of each month (eg, 2020-01-01), I want to calculate the date of the previous month (eg, 2019-12-01) and the date before the previous month (eg, 2019-11-01). In the expression builder, do we have any function to handle it? Thank you
You can use subMonths function, something like:
subMonths(toDate('2020-01-01'), 1)
subMonths(toDate('2020-01-01'), 2)
I have a date column called Close_Date.
How do i get the Close_date to only give me date for end of the current week?
Thanks
You can use the Last_Day function. There is a parameter WEEK_START that affects which day is the last day of the week. Here is the link below:
https://docs.snowflake.net/manuals/sql-reference/functions/last_day.html
ALTER SESSION SET WEEK_START = 6;
SELECT LAST_DAY(current_date, 'week');
You can use the following SQL in your tables DDL and It will give you the Week ending date as Saturday of the Current week. For this you don't need to change session parameters every time.
SELECT TO_DATE('2021-01-01') AS DATE,
IFF(DAYOFWEEK(DATE) = 0,DATEADD(DAY,6,DATE),DATEADD(DAY,-1,LAST_DAY(DATE,'week'))) AS Week_Ending_Dt
Change DATE as per your need.
How can I calculate the number of weeks and days from today to a chosen date on a date picker? I tried to use weekOfMonth and day properties but they don't exist.
simpleDatePicker.weekOfMonth
simpleDatePicker.day
So I have an object (Activity) where I allow users to select start date and an expiry date for an activity.
The user is basically a center/centre that provides activities for the public.
They have the option of making these activities seasonal. So for example an activity could run from Feb 01 to June 22. I use the current date along with a bunch of code to determine if the activity is in season or not.
So for example I check if the current date 271014 is greater than the start date 020114 and less than the expiry date 062214. If it is then it means the date is in range.
The issue:
I've had to make changes, so now the user must select a month and day only. This is fine until they select something like Nov 01 to Feb 28.
These dates would be in the format 1101 and 2802.
Without the year this obviously gives me different results. With the year I would have been able to determine that the expiry date Feb 28 was the year after the start date and not the same year. Then when working out if the current date was within the start date and expiry date I'd get expected results. Without the year the expiry date is now actually not greater than the start date even though it should be.
What I'm currently doing
How do I solve this issue? All I really need is to allow a user to set a start date and an expiry. The activity will show up in a table view only when the current date is in range.
If only an expiry date is selected then the activity will remain active until that expiry date has been reached. Even if I set and expiry date for Feb 28 and we're in November. The same need applies to the start date too.
Would appreciate some insight here.
Thanks for your time.
Here my suggestion (in pseudo-code): Convert all dates to strings in the format "MMdd", in
your example
startDate = "1101" // November 1
expiryDate = "0228" // February 28
currentDate = "1027" // October 27
If startDate <= expiryDate then the range is within the same year and you can check
the current date with
if (startDate <= currentDate && currentDate <= expiryDate) ...
Otherwise the range starts in one year and ends in the next year, and you check with
if (currentDate >= startDate || currentDate <= expiryDate) ...
I have 2 date pickers. One is for selecting a start date and the other is for selecting an expiry date. When a selection has been made I convert the date to string format and store the results in a two text fields.
This is how I save to the database:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMMM d" // e.g. September 15
let sDate = dateFormatter.dateFromString(startDateField.text) as NSDate!
let eDate = dateFormatter.dateFromString(expiryDateField.text) as NSDate!
activity["startDate"] = sDate
activity["expiryDate"] = eDate
activity.saveInBackgroundWithBlock({ (success: Bool, error: NSError!) -> Void in
What I intend to do is have a table view display 2 sections: one showing activities that are active, and the other showing activities that are expired/not in date range.
I figured I could do this by taking the current date and checking it was within the start date and expiry date range.
My saved date from above is showing up in parse like this:
The thing is, I don't want to take the year or time into account. The only thing that matters is the month and day. So for example an activity could run once a year between September 15th and December 20th.
I need a way to check that the current date is within those two dates taking the day (e.g. 15th) of the month into account. So today's date is October 19 and an activity would be in range if its start date was September 15 and its expiry date December 20, but would be out of range/operation if the expiry date was October 18 or start date was October 25.
So to summarise:
I will be displaying two sections in a table view. One with active activities and another with non-active out of operation activities.
How do take my stored start date and expiry date and easily check the current date is within their range?
For the occasions when users pick either a start date or expiry date I need to check if the current date is greater/less than the start date (to be able to decide if the activity should show up or not) or if the current date is greater/less than the expiry date (to be able to decide if the activity has passed or not passed its expiry date.
It would be nice if I could roll 1 and 2 into one function and use it in the table view.
Would be interested to learn how the more experienced programmer would achieve this.
Instead of the date format "MMMM d" (e.g. "September 15"), you can convert the dates
to a string with the date format "MMdd" (e.g. "0915"). Then you can do a simple
string comparison between the current date, the start date and the expiry date.
For example,
"0915" < "1019" < "1220"
so October 19 is in the range from September 15 to December 20.