How do you get the day out of a Date object since "getDay()" is deprecated? - android-studio

When the user opens my app the date is recorded. Then it's compared with the last date that was recorded. I want to be able to tell if just the day changed between the 2. And I don't want to simply see if 24 hours lapsed. The user should be able to open the app at 11:59pm, and then again in 2 minutes and the code should tell that the day has changed. Thanks for your help!

I found a solution that solves my problem (although technically doesn't directly get the day out of the Day object.)
Comparing two java.util.Dates to see if they are in the same day
Basically make a Calendar object and call it's "setTime()" method with my Date object as the argument, then use ".get(Calendar.DAY_OF_YEAR) to get the day from each Calendar object.

You are right, and if you want to get the actual day you just need to use Calendar.getInstance() like this:
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH);

Related

Power Automate: Send reminder out 3 months in advance

I have a Microsoft List that has a column called Expiration Date (text in format of MM/DD/YYYY) and Point of Contact (text in format of email#domain.com). How do I create a flow that sends an email out to the Point of Contact 3 months in advance?
My idea was to create a scheduled cloud flow that:
Repeats every day
Looks at every row in specific list
Compares if Expiration Date - 3 Months = Today
If True, send email to Point of Contact
I am currently stuck on step 3 to compare the date. I did Subtract from time to subtract 3 months from Expiration Date but now I do not know how to use this value to compare to today's date.
A better approach is to filter the list by using an OData filter. That will result in a list with all the elements you need.
For doing so, you need to specify the "Filter Query" field (in red):
First type
ExpirationDate eq ''
Then, between the quotes, add an expression, and select the functions addDays and utcNow in the following way:
addDays(utcNow(),92,'MM/dd/yyyy')
Please notice the following:
I'm adding 92 days to get the same day three months in advance for today (today is Oct 18th, so I'm looking for Jan 18th). Maybe adding just 90 days would work for you.
If you just want to add 3 to the month, you would need to get today's date to a variable with utcNow('MM') to get only the month, add 3 to it, and then create the expression accordingly.
I'm sorry the UI is in spanish. I'm from Mexico. But it's the same idea.
In the image, it reads "ExpirationDateText" because that's the way I named the field in my example. In your case, "ExpirationDate" should work.

Add Dynamic Content - Azure Data Factory ADF

I need to add a Dynamic Content in an ADF. In such a way that it needs to get last month date as below formate.
Result: 2018-12.csv.zip
If you set the date to the 28th and then subtract 30 days, that should get you into the previous month from any date. Then simply format as yyyy-MM, eg
#concat(formatDateTime(adddays(formatDateTime(utcnow(), 'yyyy-MM-28'),-30),'yyyy-MM'),'.csv.zip')
This can be done by using https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions.
Possible solution:
I will suggest you to use 3 parameters here.
This solution use trigger().startTime, but you can use utcnow() aswell.
Note: adddays(trigger().startTime,-31,'MM') will return 12 as month, as that month was 31 days ago. If your trigger is on 5th of the month, or on the first day in the month than you can use -2.
processYear = #formatDateTime(adddays(trigger().startTime,-31), 'yyyy')
processMonth = #formatDateTime(adddays(trigger().startTime,-31), 'MM')
result = #concat(pipeline().parameters.processYear,'-',pipeline().parameters.processMonth,'.csv.zip').
Hope that this helps.
#concat(formatDateTime(subtractFromTime(utcNow(),1,'Month'), 'yyyy-MM'), '.csv.zip')
Above given case works, if I know the date but I am running my Data Factory every day. So below works better.
#concat(substring(string(if(equals(int(formatDateTime(utcnow(), 'MM')),01), sub(int(formatDateTime(utcnow(), 'yyyyMM')),89),sub(int(formatDateTime(utcnow(),'yyyyMM')),1))),0,4),'-',substring(string(if(equals(int(formatDateTime(utcnow(), 'MM')),01), sub(int(formatDateTime(utcnow(), 'yyyyMM')),89),sub(int(formatDateTime(utcnow(),'yyyyMM')),1))),4,2),'.csv.zip')
Any changes appreciated.

Excel Date function and Time function in one formula

I have the following formula
DATE(YEAR(E687);MONTH(E687);DAY(E687))
and I want to use the TIME function as well. E.g:
DATE(YEAR(E687);MONTH(E687);DAY(E687)) - Time(10;0;0)
The reason is that I have guys working on my Excel sheetfrom CAT and PST
I am getting a date from the server and if a PST user adds data I want to minus 10 hrs from the server date to ensure I get the correct data in CAT.
I know my date above only shows date and not time but I want to remove 10hrs so see if it was done the previous day or the same day.
As comments on post suggests make sure your excels separation symbol e.g ; or , - Check regional settings.
Worked!

How to get number of days between two dates in nodatime

I need to compute the number of days between two dates using NodaTime, and to do it in a timezone.
The end time is date based with an implied time of midnight at the end of the day. This date is in a timezone.
The start time is the current time, but I am passing it into the function so that the function is testable.
I tried using Period, which seems like the obvious answer, but Period is too granular on one end (when we are on the end day) and not granular enough when we are more than 1 month away.
So if Now is July 9, 5:45pm in America/Toronto and the End Time is Sept 1, 00:00:00, then I would like to be able to calculate 54 days. (assuming I counted the number of days on my calendar correctly. :) )
I figured I would have to handle the sub day problem myself, but it surprised me when I had to figure out how to handle the greater than a month problem.
Is there an obvious way to get the number of days between two times from NodaTime? I have it down to three lines of code using .Net's DateTime and TimezoneInfo classes, but I want to move to NodaTime for all the reasons specified on the site.
Thanks
I should have read the Arithmetic section of the docs more closely before posting.
You can specify which unit you want the math result to be in with a 3rd parameter. Here is what I needed:
Period timeLeft = Period.Between(nowInTz.LocalDateTime, endDate, PeriodUnits.Days);
this is from the docs:
http://nodatime.org/unstable/userguide/arithmetic.html
Hope this helps somebody else in the future.

LWUIT Calendar. set time on selected date and find difference in milliseconds

I have loaded the calendar in my LWUIT based UI. Thanks to this thread. It is neat.
when i select a certain date i want the calendar to close and the selected date to appear in my original form in dd-mmm-yyyy form.
I want to take this selected date, set the clock to 1200 hrs (afternoon) on that day and find the time in milliseconds elapsed between now and 1200 hrs on the selected date.
something i have earlier asked here but for a desktop java applications using netbeans 7.1.2.
I find that methods like getInstance, getCalendar, setTime, are not supported in the LWUIT calendar. Are they? I can only have date = getDate(); but cant set the clock on that date.
Further,
1. How to select current time (now) in milliseconds.
Will this work?
`Calendar today = Calendar.getInstance();
Date time_now = today.getTime();`
If it will, How do i find the difference between the date selected by user and time_now. (supposing that i simply add (12*60*60*1000) to the above difference to compensate for inability to set the clock to mid-day.) The real problem is that, above two objects are date objects and i want the difference in milliseconds as a double or long variable.
Whats the solution. Thanks in advance.
You are confusing the LWUIT com.sun.lwuit.Calendar class and the java.util.Calendar class, they have similar names but they are quite different. You can just use the java.util.Calendar class by typing in its fully qualified name.
Keep in mind that the java.util.Calendar class in J2ME is more limited than the one in Java SE but can still be used to some degree.

Resources