Is it possible to convert a German date? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Is it possible to convert a German date?

Post by mrdigitalis » 26 May 2022, 08:24

Dear members,

Is it possible with FormatTime to add an inputdate like: 31.01.2022 (this is how Germans write a date) to this outputdate: YYYYMMDD ?

I have no clue how to do that. Can somebody please help me on my way with it?

Thanks in advance!

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Is it possible to convert a German date?  Topic is solved

Post by BoBo » 26 May 2022, 08:45

Code: Select all

d := StrSplit("31.01.2022",".")
MsgBox % d.3 d.2 d.1
Und hier für Profis: https://github.com/Paris/AutoHotkey-Scripts/blob/master/DateParse.ahk

mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Re: Is it possible to convert a German date?

Post by mrdigitalis » 26 May 2022, 09:25

@bobo wow that simple! Thank you very much!

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Is it possible to convert a German date?

Post by Rohwedder » 26 May 2022, 14:10

Hallo,
my method to calculate dates with known TimeStamps:

Code: Select all

GTimeStamp = dd.MM.yyyy ;Germans write a date
MsgBox,% Date := TimeStamp("31.01.2022",GTimeStamp)
; 20220131120000 (Noon if time not given)
Date += 1234, days ;EnvAdd
FormatTime, Date,% Date, %GTimeStamp%
MsgBox,% Date ;18.06.2025 = 31.01.2022 + 1234 days

TimeStamp(Date, Format:="")
{
    Static Noon := A_Year A_MM A_DD 120000, Down := 7060504030201, FOld                                                          
    FormatTime, D,% 8 Down,% Format?FOld:=Trim(Format):FOld  
    For all, V in ["Date","D"], Date := Trim(Date) ; add missing leading zeros
        %V% := RegExReplace(%V%, "(?<=^|\D)(\d)(?=\D|$)", "0$1")
    Loop, Parse,% (0 Down, N := Noon) ; today's noon
        IF A_LoopField And Pos := InStr(D, A_LoopField)
            N := SubStr(N,1,A_Index-2) SubStr(Date,Pos-1,2) SubStr(N,A_Index+1)
    Return, N ; digits >0 from Down in D stand for Date's values
}

mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Re: Is it possible to convert a German date?

Post by mrdigitalis » 29 May 2022, 03:55

Danke auch! @Rohwedder

Post Reply

Return to “Ask for Help (v1)”