How can I convert a ColdFusion date to Unix Timestamp?
myDate = DateAdd("m", -1, Now());
I would like to convert myDate to unix timestamp using ColdFusion
Thanks
Just create the UNIX origin date, and do a DateDiff from then to now (or whatever your date variable is) in seconds.
<cfset startDate = createdatetime( '1970','01','01','00','00','00' )>
<cfset datetimeNow = dateConvert( "local2Utc", now() )>
<cfset UnixStamp = datediff( 's', startdate, datetimeNow )>
Since CF stores DateTime objects as Java Date objects, this also works:
var unixStamp = int( now().getTime() / 1000 );
getTime() returns milliseconds, which is why I divided by 1000 and rounded using int().
So, specifically for the example in the OP:
var unixStamp = int( myDate.getTime() / 1000 );
Related
I have defined a measure as
Measure = sum('Combined FL'[login hours (Minutes)])
How do I convert the minutes to HH:MM:SS format?
You can try this measure:
Formatted Duration (HH:MM:SS) =
VAR _mins = SUM ( 'Combined FL'[login hours (Minutes)] )
VAR _hrs = QUOTIENT(_mins, 60)
VAR _min = MOD(_mins, 60)
RETURN FORMAT(_hrs, "00") &":"& FORMAT(_min, "00") & ":00"
I need some help with my measure counting correct in total.
This is the MainTable:
With my Measure "CountPass" I count every ID distinct with the action "pass":
CountPass = CALCULATE(DISTINCTCOUNT(Workflow[ID]),Workflow[action]="pass")
Furthermore with my Measure CountPassPreweek I do same with reference on previous Week by using the a date table:
CountPassPreweek =
var currentweek = SELECTEDVALUE(DateTable[WeekNum])
var currentweekday = SELECTEDVALUE(DateTable[WeekNo])
var currentyear = SELECTEDVALUE(DateTable[Year])
var maxweeknum = CALCULATE(MAX(DateTable[WeekNum]),all(DateTable))
Return
SUMX(
if(currentweek = 1,
DateTable[WeekNo] = currentweekday && DateTable[WeekNum] = maxweeknum && DateTable[Year] = currentyear - 1,
DateTable[WeekNo] = currentweekday && DateTable[WeekNum] = currentweek -1 && DateTable[Year] = currentyear)),
[CountPass]
)
This is working so far but not showing the totals, so I have a second measure for doing that:
CountPreweekTotal =
var _table = SUMMARIZE(DateTable,DateTable[Date],"_value",[CountPassPreweek])
return
SUMX(_table,[_value])
And here you see my problem: The measure doesn't count distinct like the "original" counting Measure as you see here
Hope somebody can help me with that.
Thanks a lot!
It's counting 3 since abc is getting counted twice the way your measure is written (since dates are separated in your SUMMARIZE).
Since you appear to have a proper date table, you should be able to use time intelligence functions to write this much more simply as
CountPassPreviousWeek =
CALCULATE ( [CountPass], DATEADD ( DateTable[Date], -7, DAY ) )
This should work for the total too.
I am using this formula to Convert Seconds into D:H:M:S but if its blank or 0 i would like the ::: to not show up. any help would be appreciated.
2. String AVG Duration =
var vSeconds=[1. Time Lapse Sec M AVG]
var vMinutes=int( vSeconds/60)
var vRemainingSeconds=MOD(vSeconds, 60)
var vHours=INT(vMinutes/60)
var vRemainingMinutes=MOD(vMinutes,60)
var vDays=INT(vHours/24)
var vRemainingHours=MOD(vHours,24)
return
vDays&":" &
vRemainingHours&":"&
vRemainingMinutes&":"&
vRemainingSeconds& ""
Image
... Return
if ( isblank ([1. Time Lapse Sec M AVG]) || [1. Time Lapse Sec M AVG] = 0
, blank (), vdays&":"&vRemainghours...
You can simplify this quite a bit with FORMAT.
2. String AVG Duration =
VAR seconds = [1. Time Lapse Sec M AVG]
VAR days = INT ( seconds / 86400 )
VAR partial = seconds / 86400 - days
RETURN
IF (
NOT ISBLANK ( seconds ),
FORMAT ( days, "0:" ) & FORMAT ( partial, "hh:nn:ss" )
)
I have the below table and calculating the durations between First_change_Date and Create_date using this DAX formula:
Response_time =
VAR Minutes = DATEDIFF('otrs ticket Response'[otrs ticket.create_time], 'otrs ticket Response'[First_Change_time],MINUTE)
var days =INT(Minutes/1440)
var hourNo=INT(MOD(Minutes,1440) / 60)
var minuteNO=MOD(Minutes,60)
RETURN
CONCATENATE( CONCATENATE( CONCATENATE(days,"d "), CONCATENATE(hourNo, "H ")), CONCATENATE(minuteNO, "m "))
I want to exclude the weekends (Friday, Saturday in my case) and non working hours (5:00pm - 9:00am)
Data:
For my client, I have created a logic. First created a WorkingHoursTable.
Then created a calculated column with the following formula, in the table which has the start and end dateTime's.
Working Hours Between Dates =
var startDate = [yourStartDateTime].[Date]
var startTime = [yourStartDateTime] - startDate
var endDate = [yourEndDateTime].[Date]
var endTime = [yourEndDateTime] - endDate
var firstFullDay = startDate + 1
var lastFullDay = endDate - 1
var inBetweenWorkingHours =
IF(
firstFullDay > lastFullDay,
0,
SUMX(CALENDAR(firstFullDay, lastFullDay), LOOKUPVALUE(WorkingHoursTable[WorkingHoursInAllDay], WorkingHoursTable[WeekDay], WEEKDAY([Date], 2)))
)
var firstDayStart = LOOKUPVALUE(WorkingHoursTable[StartTime], WorkingHoursTable[WeekDay], WEEKDAY(startDate, 2))
var firstDayEnd = LOOKUPVALUE(WorkingHoursTable[EndTime], WorkingHoursTable[WeekDay], WEEKDAY(startDate, 2))
var lastDayStart = LOOKUPVALUE(WorkingHoursTable[StartTime], WorkingHoursTable[WeekDay], WEEKDAY(endDate, 2))
var lastDayEnd = LOOKUPVALUE(WorkingHoursTable[EndTime], WorkingHoursTable[WeekDay], WEEKDAY(endDate, 2))
var effectiveStartTime = IF(startTime < firstDayStart, firstDayStart, startTime)
var effectiveEndTime = IF(endTime > lastDayEnd, lastDayEnd, endTime)
return
IF(
startDate = endDate,
24 * IF(effectiveEndTime > effectiveStartTime, effectiveEndTime - effectiveStartTime, 0),
var firstDayWorkingHour =
24 *
IF(
startTime > firstDayEnd,
0,
firstDayEnd - effectiveStartTime
)
var lastDayWorkingHour =
24 *
IF(
endTime < lastDayStart,
0,
effectiveEndTime - lastDayStart
)
return firstDayWorkingHour + lastDayWorkingHour + inBetweenWorkingHours
)
In this formula you just set the first 4 variables correctly. Then it will calculate total working hours. Unit will be in hours.
Edit: As I see from your post that your weekends are Friday and Saturday, you will need to use WEEKDAY functions slightly different. You can send 1 as a second parameter to WEEKDAY function, instead of 2. You will also need to modify the WeekDay column of WorkingHoursTable.
After this one, you can parse it to '9d 20H 52m' with your formula.
I split the date/time in to date and time columns. I then use a date dimension, where one of the columns is "Is Working Day" = TRUE(), based on which day of the week it is (a simple calculated column). In the time dimension, you do the same to identify "Working Hour" = TRUE(), again, a simple calculation.
Once you have the dimensions in place it then becomes very easy to build your calculations to include / exclude.
I have a table that I am trying to convert into a gantt chart. This table contains the task order (sometimes the same for those in parallel), as well as a task duration (by quarter).
If I have a Project Start Date = 1/1/2020, how could I calculate the Start & End dates for each subsequent task?
Example,
Task A: Order = 1, Duration = 4 ---> Start = 1/1/2020, End = 1/1/2021
Task B: Order = 2, Duration = 1 ---> Start = 1/1/2021, End = 3/1/2021
Task C: Order = 3, Duration = 2 ---> Start = 3/1/2021, End = 9/1/2021
You can calculate the total duration elapsed using appropriate filter modifiers. Then you can use EDATE function to get the start and end dates from the project start date adding elapsed months.
Here is an example formula of start date in a calculated column.
StartDate =
VAR ProjectStartDate = Date ( 2020, 1, 1 )
VAR CurrentOrder = Tasks[Order]
-- Quarters passed since the project start date before the current task
VAR DurationElapsedBefore = CALCULATE (
SUM ( Tasks[Duration] ),
REMOVEFILTERS (),
Tasks[Order] < CurrentOrder
)
-- Multiplying by 3 to turn quarters into months
RETURN EDATE ( ProjectStartDate, DurationElapsedBefore * 3 )
The formula for end date is just replacing < with <= inside CALCULATE.