Converting DateFormula to DateTime - dynamics-365

In business central there is this data type named DateFormula, in it you can define things like '1D + 2H + 3S' (1 day, 2 hours and 3 seconds). I found out that i can convert this time range to a Date using CalcDate() however, Date objects dont contain the time information, which I do need.
There is no CalcDateTime() function in BC, nor does it mention converting DateFormula's to DateTime anywhere online it seems.
How can I convert a DateFormula to a DateTime object in BC?

OK so apparently it turns out that DateFormula datatype does not even support things like hours and seconds, only dates and no times.
Solved!

Related

Alteryx Convert String to Time

I have a column of times in ALteryx like the following:
Time
=====
8:05 AM
8:07 AM
8:11 AM
8:12 AM
8:16 AM
...
They are currently stored as a String, but I want to convert them to the Time format. So far, I have tried using the LEFT and TRIM function to isolate the time itself as such:
Trim(Left([Time], 5)," ")
However, when I try to convert this to a Time datatype, I receive type conversion errors. How can I convert something like 8:46 AM from a String to a Time datatype in Alteryx?
I did some more digging and trying different things out, and I was able to figure it out. For the reference of others, here is what I did:
DateTimeParse([VisitTime] + " " + [PartofDay],"%I:%M %P")
Where [VisitTime] is the time expressed like 8:30 and [PartofDay] is AM or PM.
After this, I used a Select tile to change the datatype from String to Time without type conversion errors.

How to read a timestamp

I have joined in a Data competition for students. They gave me timestamps of users' interaction. Is it useful?
Some of them are:
1615983880510
1615767552552
1615767577100
1616036788631
What you are looking at is a linux timestamp. It's actually a pretty interesting time representation. In short, it's just a number. And it represents the total number of seconds that have passed since January 1st 1970. A date known as "Unix Epoch Time".
Now, if you want to convert that into a readable date there are many ways to do it in basically every programing language. For example in python you might do something like this:
from datetime import datetime
def printdate(unix):
print(datetime.utcfromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S'))
BUT! It seems like your dates might actually be in miliseconds. Meaning that you might actually want to divide your dates by 1000 before passing them trough the function. So...
def printdatems(unix):
return printdate(unix/1000)
And there you go!
printdatems(1615983880510) #2021-03-17 12:24:40
printdatems(1615767552552) #2021-03-15 00:19:12
printdatems(1615767577100) #2021-03-15 00:19:37
printdatems(1616036788631) #2021-03-18 03:06:28
That's the output for the example dates you provided.
Of course you can find much more information on Wikipedia:
https://en.wikipedia.org/wiki/Unix_time
It's an intresting read!

Perform add/subtract hour/min from date time in freemaker

I am new to freemarker.
In freemarker, I would like to perform arithmetic expression on DateTime as follows:
${triggerTimestamp}-1h
But this is not working. Could anyone please help here?
FreeMarker doesn't do date/time arithmetic out of the box (as of 2.3.30 at least). It's expected that the data-model (context) contains the values that you actually want to display. One can implement some helper method in Java though.
You'll want to explore converting the date into unix/epoch time. If you add ?long to the end of the variable you'll convert the datetime into epoch time (which is in seconds) then do math and convert it back to a date. Your example would be
${(triggerTimestamp?long - 1 * 1000 * 60 * 60)?number_to_datetime?string.iso}

Any reason to use Date?

There are at least three types which represent time: Time, Date and DateTime(from ActiveSupport).
My problem is, could DateTime totally replace Date? In other words, if I can use DateTime, is there any reason to use Date instead?
require 'date'
d = Date.today
dt = DateTime.now
p Date.public_methods - DateTime.public_methods
#=>[:today]
p DateTime.public_methods - Date.public_methods
#=>[:now]
p d.public_methods - dt.public_methods
#=>[]
p dt.public_methods - d.public_methods
#=>[:hour, :min, :minute, :sec, :second, :sec_fraction, :second_fraction, :offset, :zone, :new_offset]
DateTime is a subclass of Date. Using DateTime, you lose the today Class method and get now in return. You don't lose instance methods.
If you want to store only the date, for example a birthday, or a certain day where an event takes place, then it can be easier to use only date. Then you have no troubles which arise from different time zones and time zone calculations. If you use DateTime, then if you add an offset of -2 hours to 00:00 am, you get 10:00 pm of the previous day.
Date does not store any information about the time, neither with the timezone. So you might get into trouble if at some point you'll need to use time data.
Cf this link, which I found clear about what classes should be used, when, and how.

Is there any way in XQuery to get the current time in milliseconds since some Epoch?

XQuery offers various date/time functions like current-dateTime(), however I can't seem to find one which gives me the time in milliseconds since Epoch. Functions to extract hours, minutes and seconds seem to exist too individually.
What is the right way to get the Epoch time (i.e. unix time or similar) in XQuery?
(current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT0.001S')
returns the number of seconds as a duration, and then divides by 1 millisecond to get the number of milliseconds as a number.
thank you for the tips. I modify the code for Oracle Service Bus 11g (OSB 11g) Xpath editor in case someone else needs it
{ (fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S") }
Additional tricks on Aditya's answer for OSB 11g.
There has an annoying bug on XQ Editors that will change div and operator into a , (comma).
Just put a conversion function in front of that code. such as xs:long, xs:string
ex.
{ xs:long((fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S")) }

Resources