I find that there are two ways to calculate the date in AutoHotKey:
Use EnvAdd, which is synonymous with var += value
Convert the date to the YYYYMMDDHH24MISS format, and calculate it as if it's a regular number, then convert back to date format
It seems that using EnvAdd is better, because it has a parameter to determine the time unit. (Using the second method may lead to unaccepted value, such as days 62 or month 20.) But since EnvAdd only changes the current value of the input variable, not assign the result to another variable, so if I want to have keep the original one, I have to do this:
a:=b
a+=10
This is counter-intuitive, because the original value is stored in a new variable, while it's more natural to expect the original value is stored in the old variable.
Is there a way to keep it more natural to read?
Do you mean something like this?
a:=b+10
I was confused. I should have used:
b := a
b += 10, months
Related
I am new to Pentaho, so please be gentle.
I am, perhaps naively, wanting to use a Formula to convert a six-character string in the form YYYYMM to the date representing the final day of that month.
I imagine doing this step by step using successive lines of the Formula: checking that the string is of the correct length and, if so:
extracting the year and converting it to integer (with error checking)
extracting the month and converting it to integer (also with error checking)
converting ([year], [month], 1) to a date (the first of the month)
adding a month
subtracting a day
Some of those steps may be combined but, overall, it relies on a succession of steps to achieve a final result.
Formula does not seem to recognise the values achieved along the way though, at least not by enclosing them in square brackets as you do with fields from previous objects in the mapping.
I suppose I could have a series of Formula objects one after the other in the mapping but that seems untidy and inefficient. If a single Formula object cannot have a series of values defined on successive lines, what is the point of even having lines? How do I use a value I have defined on a previous line?
The formula step isn’t the best way to achieve that. The resulting formula will be hard to read and quite cumbersome.
It’s better (and faster) to use a calculator step. A javascript step can also be used, and it will be easier to read, but slower (though that probably won't be a major issue).
So, one way forward is to implement this on a calculator step:
Create a copy of your string field as a Date
Create 2 constant fields: 1 and -1
Add 1 month to the date field
Subtract 1 day to the result
Create a copy of the result as a string.
See screenshot:
I have a character variable in the form of "Jan-17" in my table and would like to convert it to date type. Does anyone what kind of date form this is and how I could go about converting it? Thank you.
SAS date variables are stored as number of days since Jan 1, 1960. For a variable that is Month and Year only, you'd need to pick a day - many choose the 1st, some the 15th or 30th/31st, depending on your business rules.
Either way, you can use the input function as a starting place. You need to know the informat - the instructions for how to translate characters to numbers. In your case, MONYY6. will likely work, though you can also try ANYDATEDTE. to let SAS guess the date informat to use.
Then, if needed, you can adjust the date it chose based on your business rules using the intnx function, which allows you to adjust it to the 15th or end of month if you prefer.
Use the INPUT() function with the correct informat.
data have;
date_char = 'Jan-17';
run;
data want;
set have;
date_dt = input(date_char, monyy6.);
format date_dt date9.;
run;
01JAN2017
Does anyone know if DynamoDB supports calculating exponents in an UpdateExpression?
I know I can add or subtract from a column, but that seems to be the mathematical limit on updates that I can find.
I am trying to take and existing column value, take 2 to the power of that column value, and then update a second column.
Thanks
Unfortunately, you can only add/subtract. From the docs for Update Expressions:
Incrementing and Decrementing Numeric Attributes
You can add to or subtract from an existing numeric attribute. To do this, > use the + (plus) and - (minus) operators.
You'll need to perform the exponent function in your application code after reading the item.
I have 2 fields of datetimestamp type. I need to compare them based on the quarters those dates occur in and determine whether one occurs in a past, same as, or future quarter.
2 fields: pay.check_dt and pay.done_in_dt. I want to know if pay.check_dt occurs in a prior, same as, or future quarter in comparison to pay.done_in_date
I originally thought to use a case statement converting them using to_Char(fieldname, 'Q-YYYY'), but then I can't to the mathematical comparison because they are then character strings.
Thanks for the help!
Craig
Use the TRUNC(date) function: documentation
I have no DB available now, but something like:
TRUNC(pay.check_dt, 'Q') < TRUNC(pay.done_in_dt, 'Q')
I have an xts time series in R and am using the very handy function to subset the time series based on a string, for example
time_series["17/06/2006 12:00:00"]
This will return the nearest observation to that date/time - which is very handy in many situations. However, in this particular situation I only want to return the elements of the time series which are at that exact time. Is there a way to do this in xts using a nice date/time string like this?
In a more general case (I don't have this problem immediately now, but suspect I may run into it soon) - is it possible to extract the closest observation within a certain period of time? For example, the closest observation to the given date/time, assuming it is within 10 minutes of the given date/time - otherwise just discard that observation.
I suspect this more general case may require me writing a function to do this - which I am happy to do - I just wanted to check whether the more specific case (or the general case) was already catered for in xts.
AFAIK, the only way to do this is to use a subset that begins at the time you're interested in, then get the first observation of that.
e.g.
first(time_series["2006-06-17 12:00:00/2006-06-17 12:01"])
or, more generally, to get the 12:00 price every day, you can subset down to 1 minute of each day, then split by days and extract the first observation of each.
do.call(rbind, lapply(split(time_series["T12:00:00/T12:01"],'days'), first))
Here's a thread where Jeff (the xts author) contemplates adding the functionality you want
http://r.789695.n4.nabble.com/Find-first-trade-of-day-in-xts-object-td3598441.html#a3599887