Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
date decimal back to date
#1
is there a way to get the decimal (1-366) value of the date and then convert it back to a date in different formats?

Code:
Copy      Help
_s.time("%j")
An old blog on QM coding and automation.

The Macro Hook
#2
What formats?
#3
well, it's really more of a yak shaving function.
i have a directory of files that have a 6 digit YYMMDD*x*.??? name format and i want to create a dialog that'll ask for a "start" and "end" date of the files to pull. So, i thought if i took the dates, from the user input, and got the decimal numbers of each date, then took all the numbers between (and including) and converted them back to dates in YYMMDD format and fed them into a dictionary i could compare it to the array i built with the "YYMMDD" portion of the file name and pull only the files that have the dates in the filenames i need.

make any sense?
An old blog on QM coding and automation.

The Macro Hook
#4
If you'll get only 1-366, how you'll know YY?
#5
good question. i can pull that from the user input and do some hoop-jumping based on how the numbers look.

if from date =277 then 1-276 equals the next year.

there may actually be "no chance" that they could pull over 12 months of data (files), so i won't have to make the multi-year logic.
An old blog on QM coding and automation.

The Macro Hook
#6
This example converts day 100 to YYMMDD string and uses current year for YY part.

Code:
Copy      Help
int i=100

DATE d=_s.time("%Y.01.01") ;;beginning of this year
d=d+i
;out d
str s
s.time(d "yyMMdd")
out s
#7
thanks.

im getting this error though

Error (RT) in Macro2: 0x80020005, Type mismatch.
An old blog on QM coding and automation.

The Macro Hook
#8
Maybe "%Y.01.01" is not recognized in your locale. Try "01/01/%Y".
#9
crazy americans and their date formats!

"01/01/%Y"


thanks!!
An old blog on QM coding and automation.

The Macro Hook
#10
DELETED...didn't read post above clearly enough!!
#11
I got the from date to day of the year with this:

Code:
Copy      Help
DATE d="01/24/08"

str s
s.time(d "%j")
out s

Now to just get back...I'll work on it.
#12
Function DateFun
Code:
Copy      Help
int i=100

DATE d=_s.time("01/01/%Y") ;;beginning of this year
d=d+i
;out d
str s
s.time(d "MMddyy")
out s
Taking on Quick Macros one day at a time
#13
I had to subtract 1 from the i...but it works!

Code:
Copy      Help
DATE d="02/28/07"

str s
s.time(d "%j")
out s

int i=val(s)

DATE d2=_s.time("01/01/%Y") ;;beginning of this year
i-1
d2=d2+i

str s2
s2.time(d2 "MM/dd/yy")
out s2


Forum Jump:


Users browsing this thread: 7 Guest(s)