How to get second or days expire for some date?

Hi, please help me.
I use date utilits for get second or days to expire for some date.
Example, i want to get second to New Year 2021?
Code:
root@monitor:/home/andrian # date
Wed Apr 22 16:15:27 EEST 2020
root@monitor:/home/andrian # date +%s
1587562219
 
Thank you for the link.
How get seconds from "Wed Apr 22 16:15:27 EEST 2021" ?
Code:
root@monitor:/home/andrian # date +%s -d "Wed Apr 22 17:19:39 EEST 2021"
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]]
            [-I[date | hours | minutes | seconds]]
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
 
Use date(1) to convert the date/time to epoch seconds. Then you can do simple arithmetic to add/subtract dates. Convert the epoch seconds back to weeks, days and hours.
 
Code:
$ echo "Wed Apr 22 16:15:27 EEST 2021" |awk -F: '{print substr($3,1,2)}'
27
Is that what you're after?
No!
Code:
root@monitor:/home/andrian # date +%s
1587566566
This seconds for now date:
Code:
root@monitor:/home/andrian # date
Wed Apr 22 17:43:30 EEST 2020
So, i want get seconds for date "Wed Apr 22 17:43:30 EEST 2021"? Namely:
Code:
# date +%s -j -d Wed Apr 22 17:19:39 EEST 2021
and get 1658756656
 
Can't get it to work with the timezone for some reason:
Code:
 % date -j -f "%a %b %d %T %Y" "Wed Apr 22 17:43:30 2021" "+%s"
1619106210
Adding the timezone fails:
Code:
% date -j -f "%a %b %d %T %Z %Y" "Wed Apr 22 17:43:30 EEST 2021" "+%s"
Failed conversion of ``Wed Apr 22 17:43:30 EEST 2021'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]]
            [-I[date | hours | minutes | seconds]]
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
 
Can't get it to work with the timezone for some reason:
Code:
% date -j -f "%a %b %d %T %Y" "Wed Apr 22 17:43:30 2021" "+%s"
1619106210
Adding the timezone fails:
Code:
% date -j -f "%a %b %d %T %Z %Y" "Wed Apr 22 17:43:30 EEST 2021" "+%s"
Failed conversion of ``Wed Apr 22 17:43:30 EEST 2021'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]]
            [-I[date | hours | minutes | seconds]]
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
So! Thank you! You super! What you need!
 
Use the numeric equivalent for the timezone. EEST = +0300

date -jf "%a %b %d %T %z %Y" "Wed Apr 22 17:43:30 +0300 2021" "+%s"
 
Yes, unless EEST isn't a valid timezone name I would think %Z should be able to convert it though.

Code:
     %Z    is replaced by the time zone name.

     %z    is replaced by the time zone offset from UTC; a leading plus sign
           stands for east of UTC, a minus sign for west of UTC, hours and
           minutes follow with two digits each and no delimiter between them
           (common form for RFC 822 date headers).

Edit: It might have something to do with daylight-savings. More specifically when this switch happens:
Code:
dice@hosaka:~ % date -j -f "%a %b %d %T %Z %Y" "Wed Apr 22 17:43:30 CEST 2021" "+%s"
1619106210
dice@hosaka:~ % date -j -f "%a %b %d %T %Z %Y" "Wed Apr 22 17:43:30 CET 2021" "+%s"
Failed conversion of ``Wed Apr 22 17:43:30 CET 2021'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]]
            [-I[date | hours | minutes | seconds]]
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

CET would be the wrong timezone for 22-April.
 
Back
Top