How do I change constraints in a dojo DateTextBox dynamically? - date

I tried to do this:
dojo.mixin(endDate.constraints, {min: new Date(2009,09,14)});
But as a result I got this:
min Wed Oct 14 2009 00:00:00 GMT+0200 (CET)
??? It always adds one month! Is this a bug?
But what I actually want to do is something like this:
dojo.mixin(endDate.constraints, {min: dijit.byId("beginDate").date});
This results in:
min undefined

It's not a bug - it's a feature! And it's not a feature of Dojo, but JavaScript:
Integer value representing the month,
beginning with 0 for January to 11 for
December.
In order to debug that error, just use FireBug to see 1) what dijit.byId("beginDate").date returns - a string or a date object?, 2) if it's a string, is it correctly formatted; can new Date parse it?, etc...

Ben, as for the second part of your question, there is no date property on a DateTextBox. What you want is the value attribute
dijit.byId("beginDate").attr("value")
which does return a Date object.

Related

Wrong day when using day()-formula with format - PowerBI

I'm trying to find out the weekday i.e Mon, Tue, Wed etc. from a date-range formatted as yyyy mm dd
I tried to use the formula format(day(Date Table),"ddd"), but the weekday is wrong. In my example, the output of 2020.01.01 gives Sunday, but it should be Wednesday.
I think your formula is wrong:
Instead of
format(day(Date Table),"ddd")
Use
format(<Target Table>[<date column>],"ddd")
I.e. Omit the DAX DAY call. This is resulting in the day of the month (1..31) being passed to the format function.
When you use the DAY function in DAX, it returns the day of the month (1 through 31).
Thus DAY ( DATE ( 2020, 1, 1) ) = 1 which means you're trying to format the number 1 as a date. Integers are interpreted as days since 1899/12/30 when treated as a date, so 1 corresponds to 1899/12/31, which happened to be a Sunday. Thus FORMAT(1, "ddd") = "Sun".
There's no reason to get DAY involved here. You can simply write
Day = FORMAT ( 'Calendar'[Date], "ddd" )

How to convert text to date format in google sheet?

In my google sheet I have a column with dates but its in a text format. here an example what I have:
Oct 01, 2021
Dec 25, 2020
...
...
I want to convert it to a date format
01/10/2021
25/12/2020
....
I need to find the number of days from the dates in this column, by using "date in column" - now(). This does not work with the format "Oct 01, 2021" since its a text, and I am getting an error from Googlesheet.
Thanks in advance
IS
Try this formula in F2:
=ARRAYFORMULA(IFERROR(DATEDIF(
DATE(
RIGHT(E2:E,4),
MATCH(LEFT(E2:E,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0),
MID(E2:E,5,2)),
NOW(), "D")))
Update
Revised the formula, which goes in F1 and fills the column, to:
={"Days Left";ARRAYFORMULA(
IFERROR(-1 * DATEDIF( DATE( RIGHT(E2:E,4), MATCH(LEFT(E2:E,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0), MID(E2:E,5,2)), NOW(), "D"),
IFERROR(DATEDIF( NOW(),DATE( RIGHT(E2:E,4), MATCH(LEFT(E2:E,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0), MID(E2:E,5,2)), "D"))))}
which reverses the date difference values. It also handles date differences for dates either in the future, or in the past.
Use the DATEVALUE() function on a date string, then use DATEDIF() to find the difference between two dates.
=DATEDIF(DATEVALUE("Oct 01, 2020"), DATEVALUE("Dec 25, 2020"), "D")
UPDATE: To find the date between today and a date string in another cell use this example:
=DATEDIF(DATEVALUE(A2), NOW(), "D")
If cell A2 contains string Oct 01, 2020, it will return 70 for today 2020-12-10

Sas changing of date format

I have three columns with date formatted differently in SAS:
12 june 2017 00:15 - full date
2016 - only year
12 - only month
I Need to change the format of date and subtract after the dates to get results in the number of months.
for instance, "12 June 2017 00:15" - December 2016 = 7
how to do it?
As you have probably already found, there isn't a ready-made SAS date informat that will correctly handle your full date field, so you'll need to write a bit of custom logic to convert it before doing your calculation. date9. is the closest matching format I could find:
data example;
fulldate = '12 june 2017 00:15';
year = 2016;
month = 12;
/* Convert string to date9 format and input */
fulldate_num = input(
cats(
scan(fulldate,1),
substr(scan(fulldate,2,' '),1,3),
scan(fulldate,3)
), date9.
);
/* Calculate difference in months */
monthdiff = intck('month', mdy(month,1,year), fulldate_num);
run;
Convert the "full date" field to a SAS date value.
Convert the combo of year and month to a SAS date value, too.
Use the INTCK function to find the difference in months.
For example:
data dates ;
input dt $18. yy mm ;
mm_diff = intck ("mon", input (cats (yy, mm), yymmn6.), input (dt, anydtdte12.)) ;
put mm_diff= ;
cards ;
12 june 2017 00:15 2016 12
11 june 2018 00:15 2017 3
;
run ;
The log will print:
mm_diff=6
mm_diff=15
As a side note, the statement "there isn't a ready-made SAS date informat that will correctly handle your full date field" made elsewhere in this thread is incorrect. As the program snippet above shows, the ANYDTDTEw. informat handles it with aplomb. It's just incumbent upon the programmer to supply a sufficient informat width W. Above, it is selected as W=12. If you're reluctant to guess and/or count, just use ANYDTDTE32.
Regards,
Paul Dorfman
Assuming that you have three numeric variables and the first one contains valid SAS datetime values you should first convert both to valid SAS date values. You can then use the INTCK() function to count months.
nmonths = intck('month',datepart(VAR1),mdy(VAR3,1,VAR2));

groovy next() date issue

I am trying to add a groovy script in SoapUI to find tomorrow's date using next() in current date.
I am getting the date as expected for all other dates except if the date is 19.
def TodaysDate = new java.util.Date().format("yyyy-MM-dd")
log.info ">>>>>>>>>> TodaysDate="+TodaysDate
log.info TodaysDate.next()
Output:
Wed Jul 19 14:34:29 EDT 2017:INFO:>>>>>>>>>> TodaysDate=2017-07-19
Wed Jul 19 14:34:29 EDT 2017:INFO:2017-07-1:
I tried this also.
def Today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())
log.info Today
NextDay = Today.next()
log.info NextDay
Output:
Wed Jul 19 14:43:38 EDT 2017:INFO:2017-07-19
Wed Jul 19 14:43:38 EDT 2017:INFO:2017-07-1:
This next() iterator works fine for other dates. Can you help me understand what I am doing incorrect here?
The format() method returns a String. And when you call next() on a String, it increments the last character. So, character 9 is incremented to the next unicode value, becoming :.
If you want your dates in a specific format, first you call next() in a Date object, then you format it:
def TodaysDate = new java.util.Date()
log.info ">>>>>>>>>> TodaysDate="+TodaysDate.format("yyyy-MM-dd")
log.info TodaysDate.next().format("yyyy-MM-dd")
The will print TodaysDate=2017-07-19 and the next date as 2017-07-20.
Maybe it's worth using TimeCategory in your case? Take a look at this simple code sample:
import groovy.time.TimeCategory
use (TimeCategory) {
println new Date() + 1.day
}
It works fine with any date. Test it with today's date (2017-07-19) - adding 1.day will give you 2017-07-20. Hope it helps.

Checking if Date is between a range of dates - Logic Issue - BEGINNER

I have a Person object. and this person object has the following attributes;
Name
StartDate
EndDate
I am saving this Person objects to an array. This array might contain more than 100 person objects.All of the above attributes are Strings.
The following is an example of person objects in that array;
John, Tue Feb 22, Thr Mar 30
Jack, Wed Mar 09, Fri Apr 21
Jack, Thu Mar 19, Fri Dec 20
Jack, Tue Jan 08, Fri Apr 26 etc..
Now i need to will supply a date, say for example Wed 29 Mar, and i need to check if it's in the range of StartDate and EndDate in the array of persons object. I have a pseudo-code for the scenario.
The date i am going to check against the StartDate and EndDate are Strings too.
Pseudo-code:
if Startdate >= providedDate && EndDate <= providedDate {
// Add to an Array
else
//Do not add to an array
Since, the StartData, EndDate and ProvidedDate are all Strings how can i check if its Greater than or lesser than the provided date ?
Note: I need an approach that doesn't use NSPredicate
In order to compare values you need values that are comparable. You could use NSDate objects, you could cast dates into sortable character/numeric form (eg 20120425), or you could use custom objects that implement their own compare:options: methods.
Or you could write a separate compareString:string1 toString:string2 method and use the strings as you have them.
You just have to make up your mind which you want to do.
What are you being tested on here? It'd odd to have a date stored as a string. Are you meant to parse the string dates in order to compare them to the provided date? If so, I'll stay away from any kinds of date classes.
If so, I'd just split it into 3 strings -- day of the week, month, day. You don't care about day of the week.
You don't have a year so you can't do any logic about that... I guess just assume it's all in the same year. (You could do something crazy like calculate 'which recent year did this day fall on this day of the week', but come on...)
Associate each month with an integer. Let's say, using a hash map. As in Months.put('January',1), etc.
Get the number out of each date -- just convert from a string to an integer.
Then the logic for whether something is before or after a date is (if -1 is myMonth is before, 0 is they're the same, and 1 is myMonth is after)
if (Months.get(myMonth) < Months.get(providedMonth)) return -1
else if (Months.get(myMonth) > Months.get(providedMonth)) return 1
else
if (myDate < providedDate) return -1;
else if (myDate > providedDate) return 1;
else return 0;