Page 1 of 1

Manufacture code date to calendar date help

Posted: 22 Mar 2018, 20:38
by Bad husband
Working on GUI to convert a manufacturing code to the actual calendar date. Don’t know where to even start to convert the code date?

We receive goods that have a 4-digit code: 7001
- the first digit will always be the year, so the example above is 2017
- the next 3 digits represents the Julian Date of the year, above example is January 1st

So 7001 is January 1, 2017

7235 would be August 23, 2017

Currently I’m using a paper table to find the calendar date. Was wondering if Ahk could do this more quickly?

Would have to pay attention to leap years and the days change. Also the function would not go back more than 3 years so when we get to the year 2020 that it would not give a result of 2010 if the code is 0001.

Here is a table with the Julian Date
https://www.fs.fed.us/fire/partners/fep ... lendar.pdf

Thanks in advance for the great help that this forum provides

Re: Manufacture code date to calendar date help  Topic is solved

Posted: 22 Mar 2018, 21:53
by jeeswg
- It's very simple to add days to a date in AutoHotkey, it also handles leap years easily. Note: if you want the 10th day of the year, that's 1 Jan plus 9 days.
- To go from the last digit of the year to the year, in a one-liner, is quite fiddly, I think I've got it right.

Code: Select all

q:: ;'last digit of year, nth day of year' to date
;vDate4 := 7001
vDate4 := 7235
;vDate4 := "0001"
;vDate4 := 9001
vYear := A_Year
vYear := vYear - 9 + Mod(9 + SubStr(vDate4, 1, 1) - Mod(vYear, 10), 10)
vDate := DateAdd(vYear, SubStr(vDate4, 2)-1, "D")
MsgBox, % FormatTime(vDate, "yyyy MMM dd")
return

w:: ;last digit of year to year
vYear := A_Year
;vYear := 2020
vOutput := ""
Loop, 10
{
	vNum := A_Index - 1
	vYear2 := vYear - 9 + Mod(9 + vNum - Mod(vYear, 10), 10)
	vOutput .= vNum " " vYear2 "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
return

;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689

DateAdd(DateTime, Time, TimeUnits)
{
    EnvAdd DateTime, %Time%, %TimeUnits%
    return DateTime
}
DateDiff(DateTime1, DateTime2, TimeUnits)
{
    EnvSub DateTime1, %DateTime2%, %TimeUnits%
    return DateTime1
}
FormatTime(YYYYMMDDHH24MISS:="", Format:="")
{
    local OutputVar
    FormatTime OutputVar, %YYYYMMDDHH24MISS%, %Format%
    return OutputVar
}

Re: Manufacture code date to calendar date help

Posted: 24 Mar 2018, 12:44
by Bad husband
Thanks for your help works great