Formatting logic app expression for DateTime - azure-logic-apps

I am generating a file for export with the file name utcnow in the logic app expression which returns a value like this
utcNow()- "2020-06-01T15:41:15.5103915Z"
I want to convert it like "20200601154151" that means I need to remove some characters like" -","T" and millisecondsfollwed by Z,
I tried few combination of string format and I am not getting it right hoping you guys to help me.
Thanks,

There are many options for custom date formats. Here is a simple guide:
yyyy = Year (2020)
MM = Month (06)
dd = Day (01)
HH = Hour (15)
mm = Minute (41)
ss = Second (15)
Construct a format string (ex: yyyyMMddHHmmss) based on your requirements and pass it to formatDateTime:
formatDateTime(utcNow(), 'yyyyMMddHHmmss')
The resulting value will be '20200601154115'. There are many additional options at the link above.

Related

Error scatter plot time vs wind speed (data from a table) MATLAB

I am trying to make a simple scatter plot in MATLAB with time on the x-axis and wind speed on the y-axis. I loaded in my data from a text file as a table and then tried to use table2array to plot since it needs numeric values not table data. I also tried using double and got another error.
Error Message: Error using scatter (line 55) Input arguments must be numeric or objects which can be converted to double.
Error in windconversions (line 18) scatter(time,wnd_TS)
I'm not sure if having the times as strings will also be an issue.
T = readtable('allunderway.txt', 'HeaderLines', 2);
%A = table2array(T)
date = T(:,1);
time = T(:,2);
wnd_TD = T(:,10);
wnd_TS = T(:,11);
table2array(wnd_TS);
table2array(time);
%double(wnd_TS);
scatter(time,wnd_TS)
A simpler way to access the data contained within the table is to use the dot notation, as T.VarN, where N is the number of the column you are interested in.
In your code you are using only 'time' for the plot, however this consists of hours, minutes and seconds only. I suspect that for your graphical analysis you require the combination of both the date and the hours.
It is possible to perform arithmetic addition on datetimes, however it is required that the two variables have the same format. By converting both dates to format 'MM/dd/yyyy HH:mm:SS' you are actually modifying the data of the variables. However, as stated in the documentation:
Since the data in the first column of the file ("date") have no time information, the time of the resulting datetime values default to midnight. Since the data in the second column of the file ("time") have no associated date, the date of the datetime values defaults to the current date.
When you add the variables date and time together together, you can add the date ('MM/dd/yyyy') of date to the time ('HH:mm:SS') of time.
An example of datetime conversion and addition follows.
Variables date and time before conversion:
date = 05/04/2011
time = 00:00:42
After conversion:
date = 05/04/2011 00:00:00
time = 06/01/2018 00:00:42
Adding the two:
05/04/2011 00:00:42
The code which reads the table and plots the scatter graph:
%Read table.
T = readtable('allunderway.txt', 'HeaderLines', 2);
%Access data of interest from table.
date = T.Var1;
time = T.Var2;
wnd_TS = T.Var11;
%Convert variable time to datetime.
time = datetime(time,'Format','HH:mm:SS');
%Add hours, minutes and seconds to variable date.
date = datetime(date,'Format','MM/dd/yyyy HH:mm:SS');
%Add month, day and year to variable time.
time = datetime(time,'Format','MM/dd/yyyy HH:mm:SS');
%Combine date and time variables.
fullt = date+timeofday(time);
scatter(fullt,wnd_TS);
The output of the code is the required scatter graph:
You can find more information on combining date and time from separate variables here.
Why do so much extra work. You could have simply used scatter(datenum(T.time),T.wnd_TS). That should do the job and save all the extra effort.

Storing Date input values on Firebase

So this is how my code looks like
cropref.child(mycrop.name).push({
cropname:mycrop.name,
croplocation:mycrop.location,
cropplantdate:mycrop.plantdate.toString(),
cropharvestdate:mycrop.harvestdate.toString(),
})
mycrop.harvestdate and mycrop.plantdate are both date inputs from my html
<input type="date" ng-model='mycrop.harvestdate'>
<input type="date" ng-model='mycrop.harvestdate'>
to be able to put the data on my Firebase database , I need to convert it first into string
cropplantdate:mycrop.plantdate.toString(),
but the data on my Firebase database includes time and timezone
sample data
Sat Dec 12 2020 00:00:00 GMT+0800 (Malay Peninsula Standard Time)
so once I call the data from my database, I can't filter it since it's not a date anymore but a string.
How do I solve this problem so that I can filter date (which is converted to string) stored inside my database
Two options
1) Store the date in a more generic, but human readable format, so right now would be Sunday November 27 at 09:13:38
20161127091338
2) Store the date as a unix timestamp (in milliseconds) using
(new Date).getTime() / 1000
There are a lot of variants to #2 so do some research to see which is best for your use case.
You can save either answer as a string but #1 would be more easily searchable since queries wouldn't require any kind of conversions - to see todays events
queryStartingAt("20161127") and queryEndingAt("20161127")
You need to convert the date first in your Format. You can use SimpleDateFormatFormat for that.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Now you can easily format your date to this format
String mynewdate = sdf.format(mycrop.plantdate.getTime());
The Output for today would be:
2016-11-27
Of course you can reverse that back to a Calendar. I do it this way:
public static Calendar fromStringtoCalendar(String datestring){
int year = Integer.valueOf(datestring.substring(0, 4));
int month = Integer.valueOf(datestring.substring(5, 7)) -1;
int day = Integer.valueOf(datestring.substring(8, 10));
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
return calendar;
}

Timezone issues when sending Calender entries using Java mail API

We are using JavaMail API to send calendar entries. But the recipients of Outlook have time zone issues, as meetings show wrong timings. In general our approach is as follows:
First of all we have,
SimpleDateFormat iCalendarDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
we then use iCalendarDateFormat.setTimeZone(TimeZone.getTimeZone(receiverTimeZone));
Finally, we use Calendar.getInstance() for start and end to manipulate Calendar fields,
and hence we have Date startDate = startTime.getTime();
Date endDate = endTime.getTime();
When we are about to send request as per icalendar specification we have ,
"DTSTAMP:" + iCalendarDateFormat.format(startDate) + "\n" +
"DTSTART:" + iCalendarDateFormat.format(startDate)+ "\n" "DTEND:" + iCalendarDateFormat.format(endDate)+ "\n"
Is this the correct approach?. Please comment.
Thanks
tl;dr
iCalendar format tracks the date-time separately from its intended time zone. You must juggle both parts appropriately.
Always use java.time classes. Never use legacy classes like Calendar & SimpleDateFormat.
Details
Caveat: I have not used iCalendar data before. So I may be incorrect in my understanding.
Looking at pages 31-33 of the RFC 5545 spec, it seems the authors of that spec assume you always want the date-time to be recorded separately from the time zone.
A moment, a point on the timeline, needs the context of a time zone or offset-from-UTC. For example, "noon on the 23rd of January next year, 2021" is not a moment. We do not know if you mean noon in Tokyo Japan, noon in Toulouse France, or noon in Toledo Ohio US — all very different moments, several hours apart.
To provide the context of an offset, a date and time must be accompanied by a number of hours-minutes-seconds such as 08:00. For an offset of zero hours-minutes-seconds, use +00:00.
2021-01-23T12:00:00+00:00
As an abbreviation of an offset of zero, +00:00, the letter Z can be used, pronounced “Zulu”. For example:
2021-01-23T12:00:00Z
But, strangely, the iCalendar spec wants to track the date and the time-of-day separate from the time zone. So this:
2021-01-23T12:00:00
…and a time zone field elsewhere:
America/New_York
And the iCalendar spec opts for the harder-to-read “basic” variation allowed by ISO 8601, which minimizes the use of delimiters. So this:
20210123T120000
For such a string, we must parse as a LocalDateTime. This class represents a date with a time-of-day but lacking any time zone or offset-from-UTC.
DateTimeFormatter f = dateTimeFormatter.ofPattern( "uuuuMMdd'T'HHmmss" ) ;
String input = "20210123T120000" ; // “Basic” variation of ISO 8601 format.
LocalDateTime ldt = LocalDateTime.parse( input , f ) ;
To determine a moment, we must apply a time zone. I assume iCalendar uses proper time zone names (Continent/Region format) and not the 2-4 letter pseudo-zones such as PST, CST, IST, and so on.
String zoneName = receiverTimeZone ; // Variable name taken from your code example, though you neglected to show its origins.
ZoneId z = ZoneId.of( zoneName ) ;
Apply the zone to get a ZonedDateTime, a moment, a point on the timeline.
ZonedDateTime zdt = ldt.atZone( z ) ;
Going the other direction, let's start with the current moment.
ZoneId z = ZoneId.of( "Africa/Tunis" ) ;
ZonedDateTime now = ZonedDateTime.now( z ) ;
And generate string values for iCalendar.
DateTimeFormatter f = dateTimeFormatter.ofPattern( "uuuuMMdd'T'HHmmss" ) ;
String iCal_DateTime = now.format( f ) ;
String iCal_ZoneName = now.getZone().toString() ;
Never use the terrible legacy date-time classes bundled with the earliest versions of Java: Calendar, GregorianCalendar, java.util.Date, SimpleDateFormat, and so on. These were supplanted years ago by the modern java.time classes defined in JSR 310.
Hard to tell without seeing the actual content of your iCalendar file, along with the expected start and end datetime with timezone information but you seem to be generating the DTSTART in floating time (datetime with local time). Although your code sample seems to imply that you have access to the recipient's timezone (receiverTimezone), this is a very fragile approach.
Instead, you should use either the datetime with UTC time or the datetime with local time and timezone (where the timezone does not have to be the receiver timezone).
If the event is not recurring, the most simple approach is to use datetime with UTC time.
See https://www.rfc-editor.org/rfc/rfc5545#section-3.3.5 for the definition of each format.
I had same problem, for which I struggle lot. So below are my findings:
Outlook works smoothly with UTC Timezone. If we set date & time with UTC Timezone then outlook automatically converts this UTC Time into user corresponding Timezone. We will have to use 'Instant' object for DTSTART:, DTEND: and for DTSTAMP(Optional but recommended) also.
Quick Test just use "DTSTART:"+Instant.now() in ical String.
And in Java 8 for getting UTC Time java time API provides Instant.now() through which you can get your system time in UTC format. Java 8 also provides method like
a. Instant.ofEpochMilli() - This returns Instant which can directly use in ical Sting.
b. new Date().toInstant() Which returns UTC Instant object.
There are few scenarios where input date and time sources are different:
If you are fetching Date and Time from database then in this case database is not storing Timezone its only saving Date & Time. So first convert the Date & Time in that Timezone in which it was saved in database, in my case I was storing Date & Time after converting in 'EST' Timezone and Date value was of EST but time zone was not there in DB. So while fetching Date & Time value from DB I have appended Timezone in the Date value and then further converted to EPOC time using below method
public static long getEpocTimeWithTimezone(Date date) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateTimePattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(simpleDateFormat.format(date), dateTimePattern);
long epochInMilliSeconds = dateTime.atZone(ZoneId.of("America/New_York")).toEpochSecond() * 1000;
return epochInMilliSeconds;
}
Then Just Use as below code for ical String:
Instant startDt = Instant.ofEpochMilli(getEpocTimeWithTimezone(//pass your date here
)).truncatedTo(ChronoUnit.MINUTES);
Now set this Instant object(startDt) directly to "DTSTART:":
"DTSTART:"+startDt+"....then in same fashion "DTEND:" also.
In second scenario you have Date with Timezone (make sure after conversion you did not loses your actual Timezone, Like in 1st scenario after saving Date in DB we actually lost Timezone but it was showing Timezone IST that was dummy so be careful about this)
So in this case just assume myDateObject is Date object. So just get the Instant (which
will be in UTC) object from myDateObject by using toInstant() of Date class.
Instant startDt = myDateObject.toInstant().truncatedTo(ChronoUnit.MINUTES);
I am using .truncatedTo(ChronoUnit.MINUTES); because if we will not use this then
we might get some extra min or second in Meeting invite Time section.
So the final String for outlook mail should be some like:
.
.
.
"BEGIN:VEVENT\n"+
"DTSTART:"+startDt+"\n"+
"DTEND:"+endDt+"\n"+
.
.
.
VVI Note: Since Z is representation of UTC time zone, So just adding Z in the last of Time will not be UTC zoned Time, You will have to convert the Date & Time then only accurate time will come on Outlook. For verifying your Time is in UTC format or not just save the .ics attached file (which you got in Email) in local and check Date & Time are coming as DTSTART:2020-05-15T13:57:00Z or not If not then you are not converting the Date correctly in UTC.

Stata: Convert String to Date

I am relatively new to Stata. I have a string variable time that records year and month in the following format:
2000m1
2000m2
2000m3
...
2015m12
I would first like to create a date variable that looks identical (but it has to be in the date format) to the above. Second, I would like to separate year and month components into two different variables, and third, I would like to rename the month component to January, February, etc.
For the first task, the command date = date(time, "YM") returns an empty variable and I can't figure what I am doing wrong.
The function date() yields daily dates, not monthly dates or any other kind of date that isn't a daily date. See its help (help date()) which begins
date(s1,s2[,Y])
Description: the e_d date (days since 01jan1960) corresponding to s1
based on s2 and Y
s1 contains the date, recorded as a string, in virtually
any format. Months can be spelled out, abbreviated (to
three characters), or indicated as numbers; years can
include or exclude the century; blanks and punctuation are
allowed.
s2 is any permutation of M, D, and [##]Y, with their order
defining the order that month, day, and year occur in s1.
##, if specified, indicates the default century for
two-digit years in s1. For instance, s2="MD19Y" would
translate s1="11/15/91" as 15nov1991.
In essence, it needs to be told a day, month and year. You supplied a month and year, and date() won't (can't) play.
As documented at the same place, daily() is a synonym for the same function and it's good practice to use it to remind yourself (and readers of your code) of what it does.
Correspondingly, monthly() provides an easier solution to create a monthly date from string input than in your own answer. Try out solutions using display (di is allowed) on simple cases where you know the right answer.
. di monthly("2000m1", "YM")
480
. di %tm monthly("2000m1", "YM")
2000m1
Reading the documentation is crucial here. See help datetime for a start. There is a lot to explain as dates come in many different forms, but it's all documented.
See also help datetime_display_formats for how to display dates differently. (No "renaming" is involved here.) For example,
. di %tmMonth_CCYY monthly("2000m1", "YM")
January 2000
I figured out the first part. I post the answer to here for anybody who needs a reference:
gen date = ym(real(substr(time, 1,4)),real(substr(time,6,2)))
format date %tm
Try this code may be it works for you
string Date1 = String.Format("{0}", Request.Form["date"]);
string Date2 = String.Format("{0}", Request.Form["date1"]);
Date1 = DateTime.Parse(Date1).ToString("yyyy-MM-dd");
Date2 = DateTime.Parse(Date2).ToString("yyyy-MM-dd");

Saving a date field value into physical file

I have a date field which accepts system date in AS400
Display file contains a date field by *DATE
I have a physical file that has a date column.When i try saving the other fields of my screen onto this physical file,i would also like to save this system date.
But i am unable to add a field name to this inbuilt Date function.
How else can i have a date field in my display screen that will automatically accept system date and have format in DD/mm/yy format for input but internally in database it must save it as yy/mm/dd.
For the purpose of having this internal conversion in my database of date format,i have initialized a date field named "date" of length 6,Packed decimal,0 decimal position.
Please guide how to save system date from screen in this format into the physical file.
Reedited:
I have a PF of grade received date defines as follows.(Its DDS)
0004.00 A GRCVDT 6P 0
I refrain to use 'L' data type for date as i want to perform date conversion as i have above explained.
On a display file, *DATE is output-only. It cannot be read by a program.
It sounds like the database table has a decimal field called DATE; not a date field called DATE. Using a date data type will make date manipulation so much easier - see Dennis' answer for advice on that. If it is impossible to use a date data type, and you must use a decimal data type to hold the date value, look at the RPG TIME operation code. That will allow you to extract the current system date into a program variable. The exact format the date will be returned depends on your job date format setting. (WRKJOB to see that). You can use a data structure and a series of EVAL statements to rearrange the date elements if you need to.
EDIT Code sample to convert EUR to YYMMDD
d eur ds qualified
d ddmmyy 6s 0
d dd 2s 0 overlay(ddmmyy: 1)
d mm 2s 0 overlay(ddmmyy: 3)
d yy 2s 0 overlay(ddmmyy: 5)
d ymd ds qualified
d yymmdd 6s 0
d yy 2s 0 overlay(yymmdd: 1)
d mm 2s 0 overlay(yymmdd: 3)
d dd 2s 0 overlay(yymmdd: 5)
c/free
eur.ddmmyy = 020812;
ymd.yy = eur.yy;
ymd.mm = eur.mm;
ymd.dd = eur.dd;
dsply ymd.yymmdd;
*inlr = *on;
/end-free
Is this file created via DDS or SQL? If DDS, then please add the field of your choice to the DDS specs, and specify a Data Type of L:
A MYDATE L
Then use CHGPF, specifying the source file and member name; the system will add the new column.
CHGPF FILE(MYLIB/MYFILE)
SRCFILE(MYSRCLIB/MYSOURCE)
SRCMBR(MY_MBR)
Even if your file is DDS described, you could add the date column by using an SQL statement like:
alter table mytable add column mydate date not null default
(But of course, if you do that, you cannot recreate the file from DDS anymore without losing the new column)
Then in your program, just before the WRITE to the data, do:
mydate = %date
There are many assumptions here: you are using ILE, you know how to modify and recompile the program, you are using free form or can translate the "variable = value" syntax above, ...)
There are also other ways to get the system date into a file without your program having to do anything special; we actually need to know more about the application in order to help much beyond this high-level advice.

Resources