I am trying to get the day of the year in XXX format. Like on 55th day it should show 055 and on 110th day it should just show 110.
(Get-Date).DayOfYear gives just 55, but the string format that I need to work with has to have a format of XXX
Try This:
"{0:D3}" -f (Get-Date).DayofYear
more info here
Related
I want to change dynamically for below URL.
e.g let's say if I run the script in february, the url would be like below such as m-1-2023.
or if I run the script in march, the url would be like m-2-2023.
if I run the script in january 2023, the url would be like m-12-2022.
and so on.
As summary , it will be the previous month.
My URL:
https://app.contoso.com/api/v1/reports/billing/aws?filter%5Bdate_range%5D=m-1-2023
Thanks,
Use Get-Date to get a DateTime object, which has support for date arithmetics and formatting. Get last month by adding -1 months and format with .Net format strings Like so,
$d = (get-date).AddMonths(-1).ToString("M-yyyy")
$url = "https://app.contoso.com/api/v1/reports/billing/aws?filter%5Bdate_range%5D=m-" + $d
# output
https://app.contoso.com/api/v1/reports/billing/aws?filter%5Bdate_range%5D=m-1-2023
I'm new to unix and I'm trying to run print the date using:
echo "Purchase date: `date`"
but I keep getting the date in the format
Purchase date: Fri Oct 2 12:21:26 EDT 2020
but I'm trying to get it in the format of MM/DD/YYYY
A quick google search will show you lots of options but I believe you want something like: ~$ date +%m/%d/%Y
~$ 10/02/2020
%[a-z] represents formatting options.
%m - month (01..12)
%d - day of month
%Y - Full Year
'/' - Delimiter
You can see all of the date formatting options by using the help command:
~$ date --help
Objective: with a shortcut, e.g. alt+d, insert
yyyy-mm-dd Ddd
Example of Ddd: Mon
I have the following code for an Autokey script
from datetime import datetime
keyboard.send_keys(datetime.now().strftime('%Y-%m-%d'))
That only gives me the date.
How should I expand the script to get the 3 character day too?
See docs.python.org/2/library/… then use %a in the format string: e.g. datetime.now().strftime('%Y-%m-%d %a')
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).
This line dose a fine job of renaming my file but it only use the hours 00-12 and not 13-24. After 12 it begins with 01. Sins it does not append AM or PM you cant know bu just looking at the file name when it was created. I would like it to use 24h format.
dir C:\script\logged_in_users-.csv | Rename-Item -NewName {$_.BaseName+(Get-Date -f yyyy-MM-dd-hh)+$_.Extension}
In your format string, use HH instead of hh, to output hours in 24-hour format.
Swap hh for HH for 24-hour clock timestamp.
See: http://technet.microsoft.com/en-us/library/ee692801.aspx