Convert minutes to Hours and mins in coldfusion [duplicate] - date

This question already has answers here:
ColdFusion - Create Time from Number of Minutes
(2 answers)
Closed 3 years ago.
I want to convert 207 minutes to Houres and mins such as format (3 Hours 37 Mins). The User will enter 207 minutes and the output should be 3 hours and 37 mins.

Yikes at these answers.
Quick, elegant, smells like lavender:
<!--- This number is arbitrary, set it to whatever you want. --->
<cfset Minutes = 125>
<cfset HoursOutput = Minutes \ 60>
<cfset MinutesOutput = Minutes Mod 60>
<cfoutput>#HoursOutput# Hours and #MinutesOutput# Minutes</cfoutput>
Using a backslash instead of dividing normally eliminates the remainder in HoursOutput (which would be formatted by default as a long decimal number) for readability.

Here is the solution
<cfset TotalMinutes = 307>
<cfset yourrequired_format= "#TotalMinutes \60# Hr #numberformat(TotalMinutes % 60, "00")# Min" />

Related

Unix Timestamp 13 Digits : CFSET puts it to 15 : ColdFusion

UNIX Timestamp in Coldfusion becomes 15 digits
1st set and call: 1666807130469
2nd set and call: 166680713046918XYZKEY999YYY5000{"symbol":"ETHUSDT","orderQty":0.03,"side":"Sell","orderType":"MARKET"}
Changes it to 15. I think I need it restricted to 13. Easiest way. Probably something simple? Why would it change it?
<cfset unixdatetimeNow = dateConvert( "local2Utc", now() )>
#unixdatetimeNow.getTime()#
<cfset encode = '#unixdatetimeNow.getTime()#XYZKEY999YYY{"symbol":"ETHUSDT","orderQty":0.03,"side":"Sell","orderType":"MARKET"}'>

Extract from Unix time AM vs. PM [duplicate]

This question already has answers here:
How to work with Unix timestamps in Matlab?
(2 answers)
Closed 3 years ago.
I have a unix timestamp (1.500641224636246e+09) and I am not sure how to extract whether it is AM or PM time from it via MATLAB.
You can combine timeofday and datetime:
>> timestamp = timeofday(datetime(1.500641224636246e+09,'ConvertFrom','posixtime'));
>> isPM = timestamp > hours(12) + minutes(0) + seconds(0)
isPM =
logical
1

Calculating seconds since the Unix Epoch when there is no +"%s" option for the 'date' command available

I wanted to calculate the seconds since the Unix Epoch (1970-01-01 00:00:00). Usually I would use
date +"%s"
Now, on my system the +"%s" option is not available but I easily got around using some other 'date' options and parsed it using bc:
date -u +"scale=0;(((((%Y-1970)*365.2425+%j)*24+%H)*60+%M)*60+%S)/1" | bc
This is short for
years = year_now - 1970
days = years * 365.2425 + day_of_year_now
hours = days * 24 + hour_now
minutes = hours * 60 + minute_now
seconds = minutes * 60 + second_now
So far so good. Then I discovered that the result of this calculation does not match with the result of the +"%s" option. I needed to add a magic number:
date -u +"scale=0;(((((%Y-1970)*365.2425+%j)*24+%H)*60+%M)*60+%S-36936)/1" | bc
Why?
Additionally, several months later, this magic number has changed from -36936 to -99792.
Why?
I'm sure something is wrong with my maths. I do not need better solutions in other script languages but I'd appreciate if somebody could correct my maths, please. Maybe someone has the source code for date and could show me its internal algorithm for +"%s" ... ?
Here is a POSIX way that should then work on all Unix and Unix like systems:
awk 'BEGIN {srand();print srand()}'
If you use ksh93, this should also work:
printf "%(%s)T\n"
Most system will have perl installed:
perl -le 'print time'

Generating Dates between two date ranges in AWK

I need to create a list of days between a date interval.
Say for example from 2001-01-01 to 2009-12-31:
2001-01-01
2001-01-02
2001-01-03
..
2009-12-29
2009-12-30
2009-12-31
I know how to do it but maybe someone has a script already made?
If not, I will make such a script and upload it so others won't waste time on this when they need it.
I do not know awk from GnuWin32, but if the functions "mktime" and "strftime" are available, you can try the following code:
BEGIN {
START_DATE="2001-02-01"
END_DATE="2001-03-05"
S2=START_DATE
gsub("-"," ",S2)
T=mktime(S2 " 01 00 00")
if (T<0)
printf("%s is invalid.\n",START_DATE) >> "/dev/stderr"
else
{
for(S=START_DATE; END_DATE>S ;T+=86440) print S=strftime("%F",T)
}
}
The key is to convert the start date to a number meaning the seconds since the Epoch, add 86400 seconds (one day or 24 x 60 x 60) and convert back to the ISO date format.
After some trials I realized the mktime() function admits wrong dates as good (for instance, 2000-14-03).
Best regards

Easy way to convert # of months into # of years and months in Groovy

Is there an easy way in Groovy to convert months (ex: 58 months) into years and months.. 4 years, 10 months?
Thanks!
Basic concept, not really tied to any language:
58 / 12 = 4
58 % 12 = 10
Unless you are asking some sort of trick question? :-)
Here's a simple solution:
def months = 58
println "${(months / 12) as int} years, ${months % 12} months"
It doesn't handle the edge cases like using singular for one year or one month, or omitting the years/months part in case they are zero.
As an alternative you could use a Java library like PrettyTime, too.