I have to track the current system time including milli-seconds using ColdFusion 11. I am using the Now() function but it outputs the date like this {ts '2017-01-11 06:48:58'}. I need to include the milli-seconds as well. Please let me know.
The milliseconds are there and you can get to them by using the TimeFormat() function of ColdFusion. Here is some sample code showing this:
<cfscript>
currentTime = Now();
writeOutput('<p>' & currentTime & '</p>');
formattedTime = TimeFormat(currentTime,'HH:mm:ss.l');
writeOutput('<p>' & formattedTime & '</p>');
</cfscript>
<!--- which outputs the following --->
{ts '2017-01-11 13:10:03'}
13:10:03.827
The first bit of code show the standard display format that you referenced. The second bit uses the TimeFormat() function to also include the milliseconds using the l mask option.
Here is a gist of that code so you can see it in action - TimeFormat example on trycf.com
There are several formatting options available to you using that function.
Masking characters that determine the format:
h: hours; no leading zero for single-digit hours (12-hour clock)
hh: hours; leading zero for single-digit hours (12-hour clock)
H: hours; no leading zero for single-digit hours (24-hour clock)
HH: hours; leading zero for single-digit hours (24-hour clock)
m: minutes; no leading zero for single-digit minutes
mm: minutes; a leading zero for single-digit minutes
s: seconds; no leading zero for single-digit seconds
ss: seconds; leading zero for single-digit seconds
l or L: milliseconds, with no leading zeros
t: one-character time marker string, such as A or P
tt: multiple-character time marker string, such as AM or PM
short: equivalent to h:mm tt
medium: equivalent to h:mm:ss tt
long: medium followed by three-letter time zone; as in, 2:34:55 PM EST
full: same as long
From the Adobe ColdFusion documentation here
If you still need the date portion of the object then use the DateFormat() function to display that part.
Related
It is necessary to calculate the percentage of the completion of the period by the Slice of the date, i.e. 100% is from 01 to 31 days, 97% is from 01 to 30 days, etc. or 1 day is 3%.
The % period formula looks something like this ((current day - 1 day)*100)/period
Tried to describe it like this
Period = CALCULATE((TODAY()-1)*100)/sum(GKB[stat_date])
But the output is 0.11...
Since there are no separate columns Start date and End date, but only a slice element with a slider, I don’t understand how to implement this and why to start.
enter image description here
I imported a CSV file in SAS and it has a time variable.But the time variable is in numeric format like 515 which refers 05:15 , 1110 refers 11:10 and 2030 which refers 20:30.
I need to convert it into proper time format and then take out the Hour from it.I have tried:
new_time=put(time,hhmm.);
The output which i got is like 0:09 , 0:10.
Please help me out.
Try this:
data have;
input mytimevar;
cards;
515
1110
2030
;
run;
data want;
set have;
time = input(put(mytimevar, 4.) || '00', hhmmss.);
format time tod5.;
run;
How this works:
Convert timevar to text using put
Append 00 for seconds
Input as time variable using hhmmss. informat
Display with leading zeros for hours using tod5. format
A Time value in SAS is numeric whose value is the number of seconds. The display of such a value typically involves associating a time format such as TIMEw.d, HHMMw.d, MMSSw.d. There are many more.
From SAS Help (my italics)
SAS time value
is a value representing the number of seconds since
midnight of the current day. SAS time values are between 0 and 86400.
NOTE: The time formats will handle time values (number of seconds) outside the 0 to 24 hours range.
For your case of a time value (call it the csvtime) encoded as 100*hours + minutes the SAS time value can be computed using the dhms function specifying zero for the d and s arguments, and the h and m arguments parsed from the csv time using integer division and modulus arithmetic.
sastime = dhms (0, floor(cvstime/100), mod(cvstime,100), 0);
format sastime time7.; * values displayed will be rendered using hh:mm:ss construct;
In other languages, there usually occurs a function to calculate the date using the reference date and time interval. For example, in R, if the reference date is 2019/09/01, and the time interval is 2 days, then the calculated date is 2019/09/03. We can use the following date conversion function:
as.Date(2, origin = "2019-09-01")
# [1] "2019-09-03"
I was wondering if Fortran has the similar functions or packages?
The Fortran standard only provides the current date and time up to milliseconds.
call date_and_time ( [ date ] [ , time ] [ , zone ] [ , values ] )
returns the following (with default values blank or -huge(0), as appropriate, when there is no clock).
date is a scalar character variable of length 8 or more. Its first 8 characters are set to the century, year, month, and day in the form ccyymmdd.
time is a scalar character variable of length 10 or more. Its first 10 characters
are set to the time as hours, minutes, seconds, and milliseconds in the form hhmmss.sss.
zone is a scalar character variable of length 5 or more. Its first 5 characters are
set to the difference between local time and UTC (also known as Greenwich Mean Time) in the form Shhmm, corresponding to sign, hours, and minutes. For example, a processor in New York in winter would return the value -0500.
values is a rank-one default integer array of size at least 8 holding the sequence of
values: the year, the month of the year, the day of the month, the **time difference in minutes with respect to UTC, the hour of the day, the minutes of the hour, the seconds of the minute, and the milliseconds of the second.
If you need anything beyond this, you will have to currently write your own functions or, as mentioned in the comments, use one of the existing ones. Among the most prominent that I know of, there is the open-srouce library datetime-fortran here.
I need a timestamp in a special format for an API call:
Dates are converted to UTC milliseconds elapsed since 12:00:00 midnight, January 1, 0001.
My first assumption was to use:
auto now = std::chrono::system_clock::now();
std::cout << "millisceconds since epoch: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch()).count()
But of course the output is the time interval from the UNIX epoch
Thu Jan 1 00:00:00 1970
So for a now = "Wed Dec 12 13:30:00 2018" it returns 1544617800000ms.
How do I get the milliseconds elapsed since 12:00:00 midnight, January 1, 0001?
Context OSISoft API
The OSISoft API Documentation for specifying a date range is quite strange
Numeric Range Queries
The previous examples were Range Queries against string fields. Numeric values > can also be searched for with Range Queries.
The only fields that are indexed as numeric fields are the CreationDate and ChangeDate fields for the respective PI Point attributes. To index these fields > add them to the list of PI Point Attributes. This configuration may be viewed > or modified on the Settings page.
These date time values are indexed as numeric values via a conversion: Dates are converted to UTC milliseconds elapsed since 12:00:00 midnight, January 1, 0001.
In the following example query is a request for last changed date equal to or > greater than February 26th, 22:16:50.000 (This is Universal Time). This DateTime, following the aforementioned conversion, would be represented as numeric value: 63655280210000. Therefore the query submitted is:
https://MyServer/piwebapi/search/query?q=changedate:[63655280210000 TO *]
From this documention I have asked this question on how to get the milliseconds elapsed since 12:00:00 midnight, January 1, 0001.
I also linked the Question to PISquare
There is no defined way to calculate:
UTC milliseconds elapsed since 12:00:00 midnight, January 1, 0001.
Judging by the examples they are using the same algorithm as https://www.epochconverter.com/seconds-days-since-y0. To get the same result you can just add 719162 days to the unix epoch:
auto now = std::chrono::system_clock::now();
std::cout << "millisceconds since epoch: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch() + std::chrono::hours(24 * 719162)).count()
Note c++20 introduces std::chrono::days which you could use instead of 24 hours.
Depending on the resolution of your system clock you may need to cast to milliseconds before adding the offset to avoid overflows (719162 days is more than 2^64 nanoseconds).
This is easy using Howard Hinnant's date/time library:
#include "date/date.h"
#include <iostream>
std::chrono::milliseconds
convert(std::chrono::system_clock::time_point tp)
{
using namespace date;
using namespace std::chrono;
return (floor<milliseconds>(tp) +
(sys_days{1970_y/January/1} - sys_days{1_y/January/1})).time_since_epoch();
}
int
main()
{
using namespace date;
using namespace std::chrono;
std::cout << convert(system_clock::now()) << '\n';
}
convert simply adds the difference between the two epochs to the system_clock::time_point, truncated to milliseconds precision, and extracts the duration to return it as milliseconds.
This program for me just output:
63680221359193ms
The range on milliseconds is plenty big enough to handle this computation, but the range on your system_clock::time_point may not be. Thus it is important to truncate to milliseconds right away as done in the code above to avoid overflow.
I have a date field coming form source paid_date and i want it to convert as
trunc(next_day(sysdate-1,'MON')).. I need to get the NEXT_DAY here and the filed data type is date-time.
Please share your inputs.
Unfortunately, as of now, there is no NEXT_DAY equivalent in Informatica. So you have to calculate it like this in expression.
TRUNC(
ADD_TO_DATE(
SYSDATE,
'DD',
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7
)
)
Explanation:
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7 - Calculates the number of days till next Monday.
ADD_TO_DATE(SYSDATE,'DD',...) - Adds the above no. of days to the input date
In this case you can use Add_To_Date function. Using this function you can get your exact date or month or year.
Formats of defining date,
Date – DD, DDD, DY and DAY
Month – MM, MON and MONTH
Year – YY, YYY and YYYY
Hour – HH, HH12 and HH24
Minute – MI
Seconds - SS
Syntax : ADD_TO_DATE (date_column, format, value)
Example: ADD_TO_DATE (Date, ‘DD’, 10)
Result:
10/01/2016 - 20/01/2016
As the format is provided as ‘DD’ and value as 10, the dates are displayed by increasing 10 days. This logics stands for date, month, year, minute, hour or seconds whatever defined in the syntax. To decrease the date value just add negative number (-10).
For you to get next day, just define
ADD_TO_DATE (Your column, ‘DD’, 1).
For more details on informatica just visit my blog,
http://etlinfromatica.wordpress.com/