i'm using autohotkey to work with date, i need to catch the day a week ago
example
if today is the 28th then I have to take the 21st of last week
calendar
in the following script I take the current date
FormatTime, date, , dd/MM/yyyy
MsgBox %date%
I even thought of a logic, to take the current day subtract by 7 that will take the day a week ago. I need help to create a better script
28 - 7 = 21
if anyone can help me thanks :)
Just subtracting numbers would be bad when you encountered a change between months.
Would have to create custom logic for that.
Luckily AutoHotkey's += operator supports date/time math.
So this is all you need:
;we're starting off the date1 variable as blank,
;which means the current time will be used.
date1 += -7, days
FormatTime, finalDate, % date1, dd/MM/yyyy ;format the result to our desired format
MsgBox, % finalDate
I did it that way
FormatTime, date_, , dd
sub += date_-7
FormatTime date, , /MM/yyyy
MsgBox,%sub%%date%
Related
I'm looking for a way to set an arbitrary date, and every time I press a key it will print the day after it (tomorrow).
global jDate = "June 1, 1986"
^+z::
;Output our date in LongDate format
FormatTime, TimeString, %jDate%, LongDate
SendInput, %TimeString%
;Increment the date by a single day
jDate += 1, Days
Return
Unfortunately, it the code keeps starting jDate as today's current date/time rather than the past date I specify in the initial variable assignment. Not sure why. The incrementing works fine, it just increments starting from todays date rather that the 1986 date.
FormatTime is expecting any date/time input to be in the "YYYYMMDD..." format. Since what you've assigned to jDate doesn't fit that criterion, it assumes it's invalid and uses today's date. To make it work how you expect, just modify your jDate input.
jDate := "19860601" ; 1986 -> YYYY, 06 -> MM, 01 ->DD
A couple of things to note: (1) global is not needed in this context; (2) I would recommend getting out of the habit of assigning variables using the = comparator (use := assignment operator instead). It only works for legacy reasons but generates more confusion than it's worth. In the context that you're using it, the quotes would need to be removed.
What is the command for displaying the time and date in qbasic? Could the syntax for the commands be given as well? And an explanation if possible?
You can use DATE$ and TIME$
These can also set the date and time as well.
The command for printing the time(current system time) is time$
The time$ is actually a function, in this case, no parameter is needed.
And the code is...
PRINT TIME$
The time is printed in hh: mm: ss format(hour: minutes: seconds).
And therefore the output would be something like this:
14:55:28
For printing the current system date, we use date$ function which is also a string function
The code is:
PRINT DATE$
The date is printed in mm-dd-yyyy format or month-day-year(American date format).
Hence the output will be:
02-17-2018
Hope it helps...
The QB date/time functions are:
DATE$ returns the date in a string in the form MM-DD-YYYY
TIME$ returns the time in a string in the form HH:MM:SS
When used as a command the date$ and time$ can be assigned to set the system date and time, for example DATE$ = "12-10-1990" or TIME$ = "12:10:10"
If the year is a leap year then the 29th day of February could be set. Otherwise if it is not a leap year then a syntax error will occur trying to set the date in February to the 29th.
I have a problem in Stata with the format of the dates. I believe it is a very simple question but I can't see how to fix it.
I have a csv file (file.csv) that looks like
v1 v2
01/01/2000 1.1
01/02/2000 1.2
01/03/2000 1.3
...
01/12/2000 1.12
01/02/2001 1.1
...
01/12/2001 1.12
The form of v1 is dd/mm/yyyy.
I import the file in Stata using import delimited ...file.csv
v1 is a string variable, v2 is a float.
I want to transform v1 in a monthly date that Stata can read.
My attempts:
1)
gen Time = date(v1, "DMY")
format Time %tm
which gives me
Time
3177m7
3180m2
3182m7
...
that looks wrong.
2) In alternative
gen v1_1=v1
replace v1_1 = substr(v1_1,4,length(v1_1))
gen Time_1 = date(v1_1, "MY")
format Time_1 %tm
which gives exactly the same result.
And if I type
tsset Time, format(%tm)
it tells me that there are gaps but there are no gaps in the data.
Could you help me to understand what I'm doing wrong?
Stata has wonderful documentation on dates and times, which you should read from beginning to end if you plan on using time-related variables. Reading this documentation will not only solve your current problem, but will potentially prevent costly errors in the future. The section related to your question is titled "SIF-to-SIF conversion." SIF means "Stata internal form."
To explain your current issue:
Stata stores dates as numbers; you interpret them as "dates" when you assign a format. Consider the following:
set obs 1
gen dt = date("01/01/2003", "DMY")
list dt
// 15706
So that date is assigned the value 15706. Let's format it to look like a day:
format dt %td
list
// 01jan2003
Now let's format it to be a month:
format dt %tm
list
// 3268m11
Notice that dt is just a number that you can format and use like a day or month. To get a "month number" from a "day number", do the following:
gen mt = mofd(dt) // mofd = month of day
format mt %tm
list
// dt mt
// 3268m11 2003m1
The variable mt now equals 516. January 2003 is 516 months from January 1960. Stata's "epoch time" is January 1, 1960 00:00:00.000. Date variables are stored as days since the epoch time, and datetime variables are stored as miliseconds since the epoch time. A month variable can be stored as months since the epoch time (that's how the %tm formatting determines which month to show).
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
I've a script scheduled every 4th and 14th day of month.
when script starts on 4th, I need to get the last day of the previous month (easy, $a.AddDays(-5))
when script starts on 14th, I need to get the last day of 2 month before.
for example:
14 april.
I want to get:28 february 2013
how is it possible?
also I want to get the date in format yyyymmdd
UDPDATE:
Is it possible that your solution doesn't work well with the change of the year?
if I'm in january, $(get-date).month -1 results 0. so I did this:
$datenow = Get-date
if $datenow.day -eq 14
$datenow.AddDays(-14)
then I calculate
$LastDayInMonth = [System.DateTime]::DaysInMonth($(Get-date).Year, $(Get-date.Month))
$datenow.AddDays(-$LastDayInMonth)
$datestring = $datenow.ToString("yyyyMMdd")
To get the date in a string:
$(get-date).Date.ToString("yyyyMMdd")
For getting the last day of two months prior:
if($(get-date).Day -eq 14){
$LastDayInMonth = [System.DateTime]::DaysInMonth($(get-date).Year, $($(get-date).Month - 2))
}
Update
The line
$LastDayInMonth = [System.DateTime]::DaysInMonth($(get-date).Year, $($(get-date).Month - 2))
Uses the static method DaysInMonth in the System.DateTime class to get the days in the month of the month that is passed to it. It's documentation is here. It takes as input two parameters, the month as an integer, and the year as an integer as well.
In our case, we want 2 months before this month, so for the month parameter we pass in
$(get-date).month - 2
And that is surrounded in a parenthesis to make sure powershell does the calculation and then pass the result of the calculation. get-date is a powershell cmdlet that gives the current date and time as a .NET dateTime object, so we have all the properties and methods at our disposal.
The whole
[System.DateTime]::DaysInMonth()
is just the way of calling static methods in powershell.
Update 2
Once you get the last day in the month, you can concatenate the string by:
$LastDayInMonthString = "$($(get-date).AddMonths(-2).ToString("yyyyMM"))$LastDayInMonth"
$(Get-Date).addDays(-$(Get-Date).Day).addMonths(-1).ToString("yyyyMMdd")