Getting current server date in Unix timestamp

Hi everyone,

I know I can use ${EPOCH} which gives me a string 1488849046 and when I convert it I get l

Tue, 07 Mar 2017 01:10:46

I want it to work this way without the time string

Tue, 07 Mar 2017 00:00:00

Pls how do I do that

Use the normal dialplan substring notation.

STRFTIME should do that:

https://wiki.asterisk.org/wiki/display/AST/Function_STRFTIME

https://www.voip-info.org/wiki/view/Asterisk+func+strftime

1 Like

@david551 I cant substring a value such 1673657262 in Unix timestamp to omit the time part of a date.

@johnkiniston Pls how do I do that using STRFTIME to get the Unix timestamp. I need the Asterisk server to get the date in this format Tue, 07 Mar 2017 00:00:00 and omit the time part. The EPOCH function will give unix timestamp of the following Tue, 07 Mar 2017 01:10:46 which is with a time part.

You just need to build a string like it says in the Wiki.

Set(MyDate=${STRFTIME(${EPOCH},GMT07,%a, %d %b %G)})

I am using America/New_York time format for the server. You think I should just omit the GMT07 position and put a comma there since I have changed the server date format to New_York

Set(MyDate=${STRFTIME(${EPOCH}, ,%a, %d %b %G)})

I used Tue, 07 Mar 2017 as an example. It should give the current date in Unix time without the time part. Assumming the time part is 00:00:00

Omitting the timezone to use will use the current timezone of the computer.

As far as I understood your original request was to format the EPOCH to your desired format of Weekday, Day of month, Year.

What is it you are trying to do if this is not the case?

I am trying to get the current system date using EPOCH which is a Unix timestamp. It works but I want the value gotten not to include a time part just the date. I am getting an exire_date in a mysql database and converting it to unix timestamp so I want to compare if server date is greater than expire_date. The expire_date in mysql database is stored this way 2017-03-04 00:00:00 but the server current date 2017-03-04 05:20:10 using EPOCH will always have a time. So I want to get the current server date in unix timestamp without a time part

Set(MyDate=${STRFTIME(${EPOCH}, ,%a, %d %b %G)})

I am converting 2017-03-04 00:00:00 in the database to Unix timestamp so the server current date must follow same order. So I think it should be Set(MyDate=${STRFTIME(${EPOCH}, ,%Y-%m-%d)})

Thank you all. I did it this way to get the current server date in unix timestamp without the time part like this

same => n,Set(GLOBAL(MyDate)=${STRFTIME(${EPOCH},%Y-%m-%d)})
same => n,Set(GLOBAL(MyDate)=${STRPTIME(${MyDate},%Y-%m-%d)})

You take a substring of the converted time.