[Cialug] Calculating dates relative to today

Andrew Denner linux-list at upeke.com
Sat Mar 2 21:56:07 UTC 2024


I know you can also abuse python to get the same results using the datetime library as a one liner.python -c "from datetime import datetime, timedelta; datetime.now() + timedelta(days=3)"
-------- Original message --------From: kristau <kristau at gmail.com> Date: 3/1/24  4:26 PM  (GMT-06:00) To: Central Iowa Linux Users Group <cialug at cialug.org> Subject: Re: [Cialug] Calculating dates relative to today OK, that sent me down a bit of a rabbit hole:kristau at pop-thelio:~$ date -d "1 Jan 2024 16:21:42"Mon Jan  1 04:21:42 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42')"Mon Jan  1 04:21:42 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42') +10 days"Thu Jan 11 04:21:42 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42') +10days"Thu Jan 11 04:21:42 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42')+10days7hours"Thu Jan 11 11:21:42 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42')+10days7hours23minutes"Thu Jan 11 11:44:42 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42')+10days7hours23minutes18seconds"Thu Jan 11 11:45:00 PM CST 2024kristau at pop-thelio:~$ date -d "$(date -d '1 jan 2024 16:21:42')+10days7hours23minutes19seconds"Thu Jan 11 11:45:01 PM CST 2024On Fri, Mar 1, 2024 at 1:55 PM Shane Nehring <shane at ntoast.com> wrote:> This can also be done with the date command:>> snehring at mamizou:~$ date -d "+90 days"> Thu May 30 14:44:07 CDT 2024>> On Fri, Mar 1, 2024 at 12:40 PM kristau <kristau at gmail.com> wrote:>> > Just discovered this nifty command-line hack to calculate dates relative> to> > today instead of using some random date-calculating website or counting> > squares on an old fashioned wall-hanger:> >> > touch -d 'X day' test; stat test> >> > Examples:> >> > *90 days from today?*> > kristau at pop-thelio:~$ touch -d '90 day' test; stat test> >   File: test> >   Size: 0               Blocks: 0          IO Block: 4096   regular empty> > file> > Device: fc01h/64513d    Inode: 46138998    Links: 1> > Access: (0664/-rw-rw-r--)  Uid: ( 1000/ kristau)   Gid: ( 1000/ kristau)> >> > *Access: 2024-05-30 13:30:47.677889558 -0500Modify: 2024-05-30> > 13:30:47.677889558 -0500*> > Change: 2024-03-01 12:30:47.677657453 -0600> >  Birth: 2024-03-01 12:30:25.265369754 -0600> >> > *90 days ago?*> > kristau at pop-thelio:~$ touch -d '-90 day' test; stat test> >   File: test> >   Size: 0               Blocks: 0          IO Block: 4096   regular empty> > file> > Device: fc01h/64513d    Inode: 46138998    Links: 1> > Access: (0664/-rw-rw-r--)  Uid: ( 1000/ kristau)   Gid: ( 1000/ kristau)> >> > *Access: 2023-12-02 12:32:53.049962148 -0600Modify: 2023-12-02> > 12:32:53.049962148 -0600*> > Change: 2024-03-01 12:32:53.047266778 -0600> >  Birth: 2024-03-01 12:30:25.265369754 -0600> >> > Might not be new to you, but it was new to me so I thought I'd share!> > --> > Tired programmer> > Coding late into the night> > The core dump follows> > _______________________________________________> > Cialug mailing list> > Cialug at cialug.org> > https://www.cialug.org/cgi-bin/mailman/listinfo/cialug> >> _______________________________________________> Cialug mailing list> Cialug at cialug.org> https://www.cialug.org/cgi-bin/mailman/listinfo/cialug>-- Tired programmerCoding late into the nightThe core dump follows_______________________________________________Cialug mailing listCialug at cialug.orghttps://www.cialug.org/cgi-bin/mailman/listinfo/cialug


More information about the Cialug mailing list