I'm using an API call to query my registrar for my domains's expiry date. The data is returned as a string, formatted DD/MM/YYYY. Mostly, this is a future date.
I wish to fire a trigger when the expiry date is 20 days or less.
How can I calculate the difference in days between today and the date value of the string returned by script (this is actually a UserParameter)?
Zabbix is not able to do it. It'll be possible, if you are able to save string DD/MM/YYYY as UNIX timestamp (it's userparameter, so it will be easy). Then the trigger will be (20days = 20*24*60*60sec = 1728000sec):
{expiry_date_unixtimestamp.last()-expiry_date_unixtimestamp.now()}<1728000
Python one liner for converting DD/MM/YYY:
echo -n "30/12/2014" | python -c 'exec("import time, sys;from time import mktime;print int(mktime(time.strptime(sys.stdin.read(), \"%d/%m/%Y\")))")'
So your userparameter should be:
UserParameter=expiry_date_unixtimestamp,<code: obtain DD/MM/YYY string, no new line at he end of string> | python -c 'exec("import time, sys;from time import mktime;print int(mktime(time.strptime(sys.stdin.read(), \"%d/%m/%Y\")))")'
Related
I have a plugin that allows adding dates from admin. I am trying to add some data into the database by running queries but I can't quite figure out how it's handling the dates. I know the plugin is saving the dates in (INT).
Example: This is the format used for generating the dates in wp-admin
12-01-2021 23:15 +0300
then end up in MySql database as (INT) value of 1610482500
Basically, all I need is to find how I can convert dates in excel or PHP to convert the dates to integers. I tried Excel Date to Number Conversion but it generates about 5 digits only. Not sure how the date is converting so any clues will be very helpful
Thanks
I have found a way.
<?php
$datetimeStr = '2021-01-12 23:15 +0300';
$datetime = strtotime($datetimeStr);
//Displays 1610482500
echo $datetime;
?>
I am trying to built a attendance app for my college where in I am fetching data for a web time-table application which has a sql backend and there the lecture start time and end time is in format 1518427800. I am not even sure what format is this.
I am using node.js to fetch from mysql and push it in firebase database, but before i pushing it in firebase. i want to convert the datetime format into something that is understandable.
I am not allowed to alter anything in the web application or its database.
It is a unix time stamp and represents the number of seconds since 1970-01-01.
You can just convert it to a number of milliseconds and pass it to the Date constructor:
var datetime = new Date(1518427800 * 1000);
As mentioned in the above answer, it is a UNIX timestamp
Using moment it is very easy to convert into a readable format
const moment = require('moment')
moment(1553939271155).format("DD/MM/YYYY") // outputs "30/03/2019"
moment(1553939271155).format("DD/MMM/YYYY") // outputs "30/Mar/2019"
moment(1553939037562).format("YYYY/MM/DD") // outputs "2019/03/30"
1518427800 is an epoch timestamp. It is the number of seconds since jan 1 1970.
you can simply convert it into the number of milliseconds
ex. 1518427800*1000
then , pass it to the DATE constructor
ex. var datetime = new Date(1518427800 * 1000);
In postgres database (9.4) i have data saved as JSON object. Including some datetime elements. In order to do time comparision in sql query I have to convert this string to timestamp. I have tried this query:
SELECT to_timestamp('2015-05-22T10:56:04.949Z','YYYY-MM-DD HH:MI:SS.MS');
-- dummy query just to test converting
OUTPUT: 2015-05-22 10:56:04.949+03
It works basically fine, except, I cant figure out how to include timezone parameter there. This string is in UTC time 10:56AM, if I run this query, I'll get 10:56 in +03 timezone (+03 is my local timezone). According to Postgres documentation, TZ should be added to format string to get timezone as well, but it does not work.
How to format this string so that it includes also timezone from initial date-time string ?
As far as I know it's not possible to parse timezone from string.
However if you know your timestamp is always in UTC timezone you can use:
SELECT to_timestamp('2015-05-22T10:56:04.949Z','YYYY-MM-DD HH:MI:SS.MS')::timestamp at time zone '00:00'
I am new to Cassandra cql (cqlsh 4.1.1, Cassandra 2.0.8.39, CQL spec 3.1.1, Thrift protocol 19.39.0) - using the cql COPY command to a table from a CSV formatted file and I get the following error: Bad Request: unable to coerce '2012/11/11' to a formatted date (long). How do I change a column using cql so that it accepts the date from my CSV file?
as Brian said, there are CQL timestamp type to follow to get CQL query running. Sometimes it looks like quite weird indeed ! I've got the same issue few weeks ago with a date time insert like this one :
INSERT INTO my_table (id,lastvisitdate) VALUES (1682221,'2012-03-25 02:26:04');
I got this error : Bad Request: unable to coerce '2012-03-25 02:26:04' to a formatted date (long) ! mmmm... so bad as the date time seems to be correct !
After many tries and before going nuts, I've just added a Z at the end of the time, Z stands for Zulu time which is also UTC and GMT :
INSERT INTO my_table (id,lastvisitdate) VALUES (1682221,'2012-03-25 02:26:04Z');
Yessss ! It works ! So do not forget the timezone in your date time values, it could be helpful ! ;-)
There is not a direct way to do that from within CQLSH.
There are a certain set of string date formats which can be coerced. See the CQL Timestamp type documentation page for some examples like:
yyyy-mm-dd HH:mm
yyyy-mm-dd HH:mm:ss
yyyy-mm-dd HH:mmZ
yyyy-mm-dd HH:mm:ssZ
yyyy-mm-dd'T'HH:mm
yyyy-mm-dd'T'HH:mmZ
yyyy-mm-dd'T'HH:mm:ss
yyyy-mm-dd'T'HH:mm:ssZ
yyyy-mm-dd
yyyy-mm-ddZ
As a workaround you could modify your CSV file to adjust the date format, then import it. (In your case it may be as simple as "yyyy/mm/dd" -> "yyyy-mm-dd".)
I have one problem... There is a table in my MySQL database that stores to-do list entries inside a JQuery-type calendar.
I had to generate a calendar_id that will generate a reminder once I created timestamp (considered as time I clicked on any of the calender dateboxes, to key in some to-do tasks - put it simple: created datetime).
This to-do list activities app is an external application that I've been working on to integrate with my own management system. I noticed that,the timestamp column is in int(11) format, so whatever timestamp entered will be converted into integer.
For example, take a look at this:
2012-02-22 15:31:24
converted to
1329899400
How can we convert datetime to this format? It's not in seconds when I tried:
intval(floor($datetime/86400));
Any help?
FROM UNIXTIME can format UNIX timestamps into datetime fields:
SELECT FROM_UNIXTIME(time)
FROM ...
The reverse function would be UNIX_TIMESTAMP.
Alternatively you can do it in PHP, if available:
To store a date into the DB format it like this:
$datetimeStr = '2012-02-22 15:31:24';
$datetime = strtotime($datetimeStr);
To retrieve it from the DB and format it to the original format, use something like this:
$dateTimeFromDB = '1329921084';
$datetimeStr = date('Y-m-d H:i:s', $dateTimeFromDB);
Here's a nice MySQL's UNIX_TIMESTAMP() function for you