Google App Script - how to set date with timezone in AdminReports.UserUsageReport.get() - date

I'm using Apps Script and trying to extract data from AdminReports.UserUsageReport.get('all', 'the date') (to get classroom last interaction timestamps), but it always comes with records from another day. For example, if I extract from the 5th, the report brings the 6th together, until 7 o'clock in the morning.
The date parameter is a string and in the documentation says the following:
Represents the date the usage occurred. The timestamp is in the ISO
8601 format, yyyy-mm-dd. We recommend you use your account's time zone
for this.
But if the parameter is a string in yyyy-mm-dd format, how am I going to pass the date with the right time zone?
This code not work:
var myDate = new Date(2021,5,5);
var timezone = Session.getScriptTimeZone();
var date = Utilities.formatDate(myDate, timezone, 'yyyy-MM-dd');
var page = AdminReports.UserUsageReport.get('all', date);
How do I use the date correctly?
Thanks a lot.

If the report dates are UTC, then each may first be converted to JavaScript Date objects using
var myDate = new Date('report_date_string');
The second two lines of your code look like they should follow correctly in converting and formatting the Dates to strings in your local time zone.

Related

Does the creation of a date object accept a parameter for a timezone?

To my understanding let date = Date() would create a date object with my current timezone. I've seen that there are certain functions where I would use a date formatter to then convert it into UTC time and add the offset to that time and then convert back into a date object but I'm wondering if there is a more elegant solution? And if not is there any other way to get the current time in another timezone in a date object without using the data formatter, as I require the calendar.component(.weekday, from: date) to find the date of the week.
If you look at the very first line on the documentation on Date, you can read the following:
A specific point in time, independent of any calendar or time zone.
So your two options when you want to deal with a local date are the DateTimeFormatter and Calendar

BCB6 How to display long date from DataSet Field in label?

I have a problem with displaying the correct date from a TDataSet.
In a TDataSet, I have a date in 'YYYY-MM-DD' format. On the computer, I have set the date in the d.mm.yy format, and so it has to stay, I can not change it.
Now, I have to take the date in the format 'YYYY-MM-DD' from the TDataSet and display it in a TLabel component in this format, but it always shows me the date in the 'YY-MM-DD' format, and that if the date is before 1969 then it adds 100 years.
I have my date in:
MyData->DataSet->Fields->FieldByName("date")
In my DB, my date is in YYYY-MM-YY format.
On my machine, I have the short date set to the 'DD-MM-YY' format, but I need to display my date in the label in 'YYYY-MM-DD' format.
I have no ideas for how to handle this.
TDateTime has a method named FormatString(). You can do this:
MyData->DataSet->Fields->FieldByName(L"date")->AsDateTime.FormatString("yyyy-mm-dd");

Date stored in different format

I have this date "2018-05-30T16:19:58.016Z" coming from my Angular app.
In Spring, the field date is as follows :
#JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date date;
The date is well stored, but with this format YYYY-MM-dd.
Is there anything that I'm missing ?
MySql date type can't hold data with timestamp. It has to be datetime in order to contain date time with timestamp data.
You probably have to specify the date format going out to the storage, as #JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") only specifies the date format for parsing the date into the Date object. Even if your Date has all of the seconds and timezone information, the default Date toString() is still
Formats a date in the date escape format yyyy-mm-dd.
according to the Java 8 docs. So if you are using that, it would most likely drop all that extra information on conversion.
You can look at this Convert java.util.Date to String for information on how to get a Date to a formatted String.

How do I set Date AND time picker in MDriven?

I am trying to capture both date and time in MDriven, but the default for data type DateTime only shows a picker (in Web) for the date, but a time is stored in the persistency layer. How do I also capture the time?
I found this in the wiki.mdriven.net
Date-formatting You set date and time format in the Style attribute
enclosed in { }.
For example, for dates and time, {short} will show date and time in
compact format. The default date format is {shortDate}. Please refer
to the Angular guide for formatting dates
https://docs.angularjs.org/api/ng/filter/date
The date and time format are automatically localized depending on the
browser.

Converting CF Session variables to a date format

Is it possible to convert ColdFusion session variables into a date format as such MM/DD/YYYY?
Right now what was created were three drop downs Month, Day, Year:
Ex. Aug 5 1986
The user wants these drop downs instead of just having one date picker. But then on the form they want that date in the format as of MM/DD/YYYY.
I have it showing as #session.checkout.info.birthmonth_1# #session.checkout.info.birthday_1# #session.checkout.info.birthyear_1#
Is it some how possible to convert those three variables into that date format?
It sounds like you want to use the CreateDate(year, month, day) function
Or in your case
session.checkout.info.birthdate = CreateDate(
session.checkout.info.birthyear_1,
session.checkout.info.birthmonth_1,
session.checkout.info.birthday_1);
The you can use a date formatting function to display as needed
#session.checkout.info.birthdate.LSDateFormat()#
Source: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/CreateDate.html