Set form & to date maximum duration for owl-date-time in angular8 - datetimepicker

I am using a range slider of Owl NG Datetime Picker (Stackblitz Example).
In this range slider, I want to set range (max duration of both dates) between from date & to date should be 10 (any int value). In other words, if I select From date Jan 1, 2020 then I can only To date between Jan 1, 2020 to Jan 10, 2020.
Also, it would be helpful if I can get an event when from or to date getting selected.
As per the documentation right now only below 4 events are available for OWL-Date-Time
Edit - I need some event/behavior like beforePickerClosed.

Related

populate date time picker from number of days

Am working in windows application.i am scanning my date barcode
i have a date barcode ..while scanning that barcode i am getting value to my textbox like this :
17197...so this value means 2017 july 16,
in that 17-year
197 -calculation of days from 2017 to july 16..
while reading this barcode i want to just populate correct date to datetime picker
how i can convert this value to date time picker..
any help is very appriciable..thanks in advance
If the first two numbers represent the year after 2000 and the following numbers represent the days from the first of january (included) of such year then
Dim test = "17197"
Dim year = Convert.ToInt32(test.Substring(0,2)) + 2000
Dim days = Convert.ToInt32(test.Substring(2))
Dim currentDate = new DateTime(year, 1, 1).AddDays(days-1)
Console.WriteLine(currentDate) ' 16/07/2017

VB.NET DatetimePicker - Wrong week number

I have an issue with my vbnet extented datetime picker.
When the element pass to new year (2016), the week number displayed on the left is wrong.
I have a "datetimepicker" which is not the default component, it was downloaded here :
http://www.codeproject.com/Articles/17063/ExtendedDateTimePicker-control-with-week-numbers
I don't understand why the calendar pass from 53 to 2 and not 53 to 1.
Maybe one of you has the same error.
Thanks for your time.
I don't understand why the calendar pass from 53 to 2 and not 53 to 1
It is pretty much working as expected. The way it is counting weeks, those first 3 days of 2016 count as the first week of 2016.
Note that the control doesnt do anything calendar or display related. It is simply changing the display style of the calendar window provided by Windows. The code seen on the CP page is all there is and mainly it just sets a style flag to tell Windows to add the week numbers:
style = style | MCS_WEEKNUMBERS;
The MSDN entry for it indicates:
Week 1 is defined as the first week that contains at least four days.
Since Jan 1-3 is not 4 days, it would seem that there is either an error, a different calendar being used or MSDN is out of date.
From comments:
From what i understood, what's wrong is "date format". Maybe it's not a 8601
No, it is more than that: ISO8601 is a different calendar which neither Windows nor NET implements. Wikipedia notes:
The first week of a year is the week that contains the first Thursday of the year (and, hence, always contains 4 January). ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.
This is what you see in the calendar drop down.
Alternative
But the ISO8601 Week Of Year is easy to calculate:
Start with the code for GetISOWeekOfYear() from my answer to a very similar question. You can use that to display the ISO8601 week of year for the selected date in a label or something next to the DTP.
Print the first and last week numbers for 2011 To 2021:
Dim cal As Calendar = CultureInfo.CurrentCulture.DateTimeFormat.Calendar
For n As Int32 = 2011 To 2017 '2021
dt = New DateTime(n, 12, 21)
Console.WriteLine(" ***** {0} *****", n)
For j = 0 To 3
Dim NetWk = cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, firstD)
Console.WriteLine("Invariant Date: {0} ISO #:{1:00} NET #:{2:00}",
dt.ToString("MM/dd/yyyy"), GetISOWeekOfYear(dt), NetWk)
dt = dt.AddDays(7)
Next
Next
The result for 2015/2016 portion:
***** 2015 *****
Invariant Date: 12/21/2015 ISO #:52 NET #:52
Invariant Date: 12/28/2015 ISO #:53 NET #:53
Invariant Date: 01/04/2016 ISO #:01 NET #:02
Invariant Date: 01/11/2016 ISO #:02 NET #:03
***** 2016 *****
Invariant Date: 12/21/2016 ISO #:51 NET #:52
Invariant Date: 12/28/2016 ISO #:52 NET #:53
Invariant Date: 01/04/2017 ISO #:01 NET #:01
Invariant Date: 01/11/2017 ISO #:02 NET #:02
Unless you are willing to write your own control from scratch or license one which can be set to a different calendar (and has a definition for ISO8601), that may be the best you can do.
The Bottomline: The Week number is not wrong. It using a different calendar than you expect/want.
References:
Get or convert NET GetWeekOfYear() to ISO week
MSDN: Month Calendar Control Styles
DateTimePicker in Reference Source
The control is working fine.
When the year changes over the final few days of the year are in week 53 - but it's not a full week. Similarly the first few days of the year are in week 1, but the control takes the system's "first day of the week" setting to determine when week 2 begins - so it is possible for the first week of the year to have any where from 1 to 7 days in it.
This means that the image you've shown is showing Week 53 because you're in December and Week 2 because the 2nd week of January does start on the 4th.
If you navigate to January it would display week 1 for the row starting on December 28.
The bottom-line is that the first week in January only has 3 days in it.
This is just the normal and correct behaviour of this control.

How can I determine if the current date is within/outside a range of two dates that don't include a year?

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) ...

Check if the current date string is within or outside the range of two other dates

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.

Lookup a value from a range of dates in excel

Please help.
We have two tables. A list of accounts and the other is a change log. I need to add a new column in table 1 where the value is the amount in table 2 for the correct account and correct validity period.
ex.
table 1:
account# beginning period ending period
1 January 1, 2012 January 31, 2012
2 January 12, 2012 February 12, 2012
table 2:
account # amount valid period beg valid period end
1 10 january 1, 2009 december 5, 2010
1 20 december 6, 2010 june 1, 2011
1 30 june 2, 2011 december 1, 2012
2 13 january 15, 2011 december 15, 2011
2 20 december 16, 2011 february 20, 2012
Thanks.
Although it is a bit complex requirement it could be done with built-in functions (although it can look a bit obscure :-) ). Specifically I mean function SUMIFS.
It has several parameters.
The first one is an area with values to be summed. It is B8:B12 in this example.
The second is an area whith values to be checked with some condition. It is A8:A12.
The third is a criterion to be applied for area from second parameter. It is (inter alia) account #.
So the formula says: sum all values from rows in B8:B12 where account # (A8:A12) is equal to desired account # (e.g. A3).
Ok, it is not all, you need specify the time range. It would be a bit clunky because you must check if two time period are overlapping (it would be easier to check if one date is in specified period).
But it could be done because SUMIFS can take another pairs of criteria range and criterion. But it cannot be used for OR condition, so you had to combine more SUMIFS.
Nice article about overlapping ranges is e.g. http://chandoo.org/wp/2010/06/01/date-overlap-formulas/
BTW: you have to format cells in B2:C3 and C8:D12 as a date to be able to compare them.