How to add 1 nano second to a timestamp - ibm-db2

How to add 1 nano second to a timestamp.
I am doing this -
select CURRENT_TIMESTAMP + '0000-00-00 00:00:01' FROM SYSIBM.SYSDUMMY1
but it does not help me.
Can anyone please help me in this ?

Related

Custom Column with multiple column references in PowerBi

Below is the dataset,
I would like to add a new column at the end of the dataset as "Covid No Vaccination Dose". This column will include of the populated data from the Covid Vaccination Dose 1, Covid Vaccination Dose 2, Covid Vaccination - Full Dose and Covid Vaccination - Booster Dose.
So basically in this scenario, there are few workers with No vaccination doses of any of the vaccines and has been identified by the said above columns.
I'm struggling to populate the answer "No" from the above said 4 Covid Vaccination columns to one Single Column which will be named as "Covid No Vaccination Dose".
Really appreciate if anyone can help me with this.
From your example, it appears that the cells will contain either Yes or No. That being the case, you can use a custom column with a formula similar to the following:
=List.Last(List.Sort(List.Distinct({[Covid Vaccination Dose 1],[Covid Vaccination Dose 2],[#"Covid Vaccination - Full Dose"],[#"Covid Vaccination - Booster Dose"]})))
If you are in powerquery with the data
Add column ... custom column ... set the column name to Covid No Vaccination Dose
and use formula similar to:
= if [#"Covid Vaccination - Dose 1"]="No" and [#"Covid Vaccination - Dose 2"]="No" and [#"Covid Vaccination - Full Dose"]="No" and [#"Covid Vaccination - Booster"]="No" then "No" else "Yes"
rather then type the [...] parts, I suggest you click on them in the right

Timestamp of yesterday at specific hour bigquery

I need to schedule a query on BigQuery, that will retrieve some data from 24h ago. The problem is that for example if its scheduled for 5am, the query needs time to be executed (let's say 2.248 seconds), and so the yesterday's data from 5:00:00.000 to 5:00:02.248 will not be retrieved. I'm using a timestamp field, and i do something like this :
SELECT *
FROM my_table
WHERE my_timestamp >= TIMESTAMP_SUB(current_timestamp(), INTERVAL 24 hour)
I would like to know if there is a way to get the yesterday's date, at a specific hour, so even if there is a little gap due to the execution, it will still retrieve data from a specific hour.
edit:
I found something :
SELECT *
FROM my_table
WHERE my_timestamp >= TIMESTAMP(DATE_SUB(current_date(), INTERVAL 1 DAY) )
AND my_timestamp < TIMESTAMP(current_date)
But this retrieves yesterday between 00:00:00.000 to 23:59:59.999
It is okay but is there a way to choose the hour ?
Consider below least verbose approach
select *
from my_table
where my_timestamp >= timestamp(current_date - 1 + interval 5 hour)
and my_timestamp < timestamp(current_date + interval 5 hour)
Okay I found on my own lol, maybe it will help someone else looking for this.
SELECT *
FROM my_table
WHERE my_timestamp >= TIMESTAMP_ADD(TIMESTAMP(DATE_SUB(current_date, INTERVAL 1 DAY)), INTERVAL 5 HOUR)
AND my_timestamp < TIMESTAMP_ADD(TIMESTAMP(current_date), INTERVAL 5 HOUR)

How create rule in AWS with CRON expression

I want to create a scheduled expression, which will start js script every week at 5:30PM PT using CloudWatch Events. I tried to insert:
- 0 30 3 * * THU *
- 0 30 3 THU
But got
Error
There was an error while saving rule getEvery1min.
Details: Parameter ScheduleExpression is not valid..
Can you help me pls?
According the docs - Schedule Expressions for Rules
Only this is work - 30 17 ? * THU *
You can't specify the Day-of-month and Day-of-week fields in the same cron expression. If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.
The cron expression should be in the below format
"Minutes" "Hours" "Day of month" "Month" "Day of week" "Year"
Based on the above cron it appears you're trying to run the cron expression only on Thursdays on the third day of the month. However if you want it to run once a week at 5:30pm you'd want something like the below.
30 17 * * THU *
Also take care to remember this expression is in UTC, so you would need to adjust it for your timezone.
For more information take a look at the Scheduled Events documentation.

Remove weekends in a formula

I want to remove weekends from a calculated column calculation. I am having a formula which calculate daily target:
Daily MAL Target = [MAL_Qtarget_A] /
(ENDOFQUARTER(Marketing_targets_MALMEL[Date]) -
ENDOFQUARTER(PREVIOUSQUARTER(Marketing_targets_MALMEL[Date])))
In the marketing Targets table thers a seperate column to identify whether the date is working day or weekday as 1 and 0.
IsWorkDay = SWITCH(WEEKDAY([Date]),1,0,7,0,1)
I want to add "IsWorkingDate=1" to the above Daily Mal Target formula. It is a calculated column. I have tried so many ways but could not do it.
Can anyone help me on this?
You can use this DAX expression to check for weekdays:
= IF(OR(WEEKDAY([Date]) = 1, WEEKDAY([Date) = 7), "Calculation for Weekdays", "Calculation for Mo to Fr")
If it's a calculated column, you can use an if condition to make the value 0 or blank for weekends:
Daily MAL Target = IF(WEEKDAY(Marketing_targets_MALMEL[Date]) in {1,7},
BLANK(),
([MAL_Qtarget_A] /
(ENDOFQUARTER(Marketing_targets_MALMEL[Date]) -
ENDOFQUARTER(PREVIOUSQUARTER(Marketing_targets_MALMEL[Date]))))
Hope this helps.

Compute end time of an activity

I have the beginning time of a surgery (new_time) in %tc format and I also have the length of the surgery (th_time) in minutes (e.g. 140 mins) and unformatted.
I would like to know how to proceed to add th_time to new_time in order to get the end time of the surgery.
Here's how I formatted so far my variables:
gen time_temp = substr(intotheatre, strpos(intotheatre," ")+1, . )
gen new_time = clock(intotheatre, "DMY hms",2050)
format new_time %tc
generate hrs=hh(new_time)
generate mins=mm(new_time)
generate secs=ss(new_time)
drop if th_time < 0 | th_time == .
drop if theatre==""
sort theatre new_time
I have read Stata Journals from Nick Cox but every attempt I made trying to generate the end_time ended up with 'type mismatch' from Stata.
Any suggestion would be appreciated!
If you have not already done so, it would benefit you to work your way through the guidance in help datetime, which is without a doubt the most visited documentation on my system, with the second-most-visited being Chapter 24 (Working with dates and times) of the Stata User's Guide PDF available from the PDF Documentation item on Stata's Help menu. Before working with dates and times, any Stata user should read the very detailed Chapter 24 thoroughly. After that, the help documentation will usually be enough to point the way. Some people may be able to remember everything without have to continually refer to the documentation, but I for one am not such a person.
With that said, your new_time variable should be created as a double
generate double new_time = clock(intotheatre, "DMY hms",2050)
as both the cited documentation and Nick Cox advise. You have new_time represented now as the number of milliseconds since 1/1/1960. Then converting the theatre time from minutes to milliseconds and adding
generate double end_time = new_time + ( th_time * 60 * 1000 )
format end_time %tc
should give you what you desire.