How to executing cron one minute after midnight every day? - unix

I want to execute cron every day on midnight at time 00:01 Hrs.
Is the following cron time correct?
1 0 * * * *

Yes the cron time is correct.
1 0 * * * /mydir/myscript
should be your cron entry.
Each cron entry consists of six fields, in the following order:
minute(s) hour(s) day(s) month(s) weekday(s) command(s)
0-59 0-23 1-31 1-12 0-6

1 0 * * * /mydir/myscript <-- Correct 1 minute after midnight
1 0 * * * * <--- Incorrect, Syntax Error

0 1 0 * * ?
or
1 0 * * *
You can generate crons example with https://www.freeformatter.com/cron-expression-generator-quartz.html

Let's get the definitions straight: cron is a daemon that is designed to run continuously and execute commands at specified intervals when you tell it to.
To do that, it needs two things: an interval and a command.
Your example has a valid interval, but is missing a command to execute one minute after midnight:
1 0 * * * * /path/to/executable/or/script/here

Related

MariaDB EVENT autoclear DB returns warning

I got MariaDB version 10.3.27 where im trying to run EVENT which starts everyday at 1am for clearing some databases. but when I try to pass lines below, it return 1 warning, but Im not sure why....
Can someone please clarify this for me? Thanks
delimiter $$
CREATE EVENT AUTOCLEAR
ON SCHEDULE
EVERY 1 DAY
STARTS (TIMESTAMP(NOW()) + INTERVAL 1 DAY + INTERVAL 1 HOUR)
DO
BEGIN
DELETE FROM ESP1 WHERE timestamp < ((UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))) + 7200);
DELETE FROM ESP2 WHERE timestamp < (UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) + 7200);
DELETE FROM ESP3 WHERE timestamp < (UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) + 7200);
DELETE FROM ESP3_1 WHERE timestamp < (UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) + 7200);
END$$
delimiter ;
Sorry my bad. Didnt enabled scheduler and not know how to read warnings...
SET GLOBAL event_scheduler=ON
fixed my problem

plsql date to number of milliseconds

Is it possible in PLSQL convert date to number of milliseconds?
I tried
select to_number(TO_CHAR(sysdate, 'yyyymmddhh24miss')) * (24 * 60 * 60 * 1000) from dual;
but I get back 1743604888943174400000
which is not the same as java GetTime method
https://www.w3resource.com/java-tutorial/util/date/java_date_gettime.php
As swmcdonnell already said, your question is kind of dublicated from:
oracle systimestamp (sysdate) to milliseconds
But you got an understanding problem. I did split your query into three columns.
SELECT TO_CHAR (SYSDATE, 'yyyymmddhh24miss'), -- Here we convert our sysdate into a 'string'
TO_NUMBER (TO_CHAR (SYSDATE, 'yyyymmddhh24miss')), -- this will output the resulting string as number - it will look the same as the 1st column
TO_NUMBER (TO_CHAR (SYSDATE, 'yyyymmddhh24miss')) * (24 * 60 * 60 * 1000) -- here you calculated 20180613150101 * 24 * 60... i think that's not what you want to do
FROM DUAL;
This doesn't make sense.
If you want the 'total-milliseconds' you have to:
use current_timestamp instead of sysdate
multiply the year (yyyy) by 365 days * 24 hours * 60 minutes * 60 seconds * 1000 ms
multiply the day-of-year (DDD) by 24 hours * 60 minutes * 60 seconds * 1000 ms
multiply the hour * 60 minutes * 60 seconds * 1000 ms
multiply the minute * 60 seconds * 1000 ms
multiply the second * 1000 ms
add ms
This would result in something like this:
SELECT to_number(TO_CHAR (CURRENT_TIMESTAMP, 'yyyy')) * 365 * 24 * 60 * 60 * 1000
+ to_number(TO_CHAR (CURRENT_TIMESTAMP, 'DDD')) * 24 * 60 * 60 * 1000
+ to_number(TO_CHAR (CURRENT_TIMESTAMP, 'HH24')) * 60 * 60 * 1000
+ to_number(TO_CHAR (CURRENT_TIMESTAMP, 'mi')) * 60 * 1000
+ to_number(TO_CHAR (CURRENT_TIMESTAMP, 'ss')) * 1000
+ to_number(TO_CHAR (CURRENT_TIMESTAMP, 'FF'))
FROM DUAL;
.. But what are u going to do with it? I don't know Java but a Timestamp should not be displayed as interval. This would be something like interval in oracle or a timespan in C#.
SELECT TO_NUMBER(TO_CHAR(SYSDATE,'YYYYMMDDHHMISS'))||to_number(SUBSTR(TO_CHAR (CURRENT_TIMESTAMP, 'FF'),0,2)) FROM dual;

get the date difference in milliseconds in oracle

I need to get he difference between end date and start date in milliseconds inside a view in oracle 11g. I can get these two dates from the database in 07-JUN-12 04.32.21.092000000 AM format. All I need is to find the diff of these kind of dates in milliseconds
SELECT ((extract(DAY FROM time2-time1)*24*60*60)+
(extract(HOUR FROM time2-time1)*60*60)+
(extract(MINUTE FROM time2-time1)*60)+
extract(SECOND FROM time2-time1)) *1000
as millisecs FROM dual;
can be done using above approach
select (DATE1 - DATE2) as days,
(DATE1 - DATE2) * 24 as hours,
(DATE1 - DATE2) * 24 * 60 as minutes,
(DATE1 - DATE2) * 24 * 60 * 60 as seconds,
(DATE1 - DATE2) * 24 * 60 * 60 * 1000 as milliseconds
from dual
EDIT - I assumed DateTime type. However, Justin Cave's question is very relevant. A Timestamp is not the same as a DateTime, so my answer won't work if you are dealing with Timestamps.
In that case, see this http://www.dba-oracle.com/t_timestamp_math_elapsed_times.htm.

How to calculate overlap week in Flex?

By using date object how we can calculate over lapping weeks?
For eg:
July 31(Tuesday) is end for the week number 38, However week number 38 ends Sunday i.e Aug 4.
However months are different
Any idea on this
Thanks all
In our Calendar component, we use this code to calculate the first date in a week; and I bet it could be modified to find the last Date of the Week. IT makes use of the DateUtils library
public static const DAY_OF_MONTH:String = "date";
/**
* This method gets the first date of the week which the given date is in.
*
* #param date This is the date for which we want to process.
* #param firstDayOfWeek The first day of the week, 0 (Sunday) - 6 (Saturday); 0 is the default. It will probably be used primarily for localization purposes.
*
* #return This returns a date representing the first day of the week.
*/
public static function firstDateOfWeek( date:Date, firstDayOfWeek : int = 0 ):Date {
var dayIncrement : int = dayOfWeekLocalized(date, firstDayOfWeek);
var returnDate : Date = DateUtils.dateAdd(DateUtils.DAY_OF_MONTH,-dayIncrement,date);
return returnDate;
}
/**
* This method returns the position of the day in a week, with respect to the firstDayOfWeek localization variable.
*
* If firstDayOfWeek is 0; then the week is display 0 (Sunday), 1 (Monday), 2 (Tuesday), 3 (Wednesday), 4 (Thursday), 5 (Friday), 6 (Saturday).
* So, a Sunday would return 0, a Saturday would return 6, and so on.
*
* If firstDayOfWeek is 1; then the week is displayed as 0 (Monday), 1 (Tuesday), 2 (Wednesday), 3 (Thursday), 4 (Friday), 5 (Saturday), 6 (Sunday).
* However, this situation will not change the date.day value. For display purposes we need a Sunday to return 6, a Saturday to return 5, and so on.
*
* This will presumably be used for display purposes.
*
* #param date This is the date to process.
* #param firstDayOfWeek The first day of the week, 0 (Sunday) - 6 (Saturday); 0 is the default. It will probably be used primarily for localization purposes.
*
* #return This returns a date representing the day’s location on the localized week display.
*/
public static function dayOfWeekLocalized( date:Date, firstDayOfWeek : int = 0 ):int {
var result : int = date.day - firstDayOfWeek;
if(result < 0){
result += 7;
}
return result;
}
To find the last date of a week, I suspect you can just call the firstDateOfWeek and add 6 days:
public static function lastDateOfWeek( date:Date, firstDayOfWeek : int = 0 ):Date {
var firstDateOfWeek : Date = firstDateOfWeek(date, firstDayOfWeek);
var returnDate : Date = DateUtils.dateAdd(DateUtils.DAY_OF_MONTH,6,firstDateOfWeek );
return returnDate;
}
Note: The second batch of code was written in a browser and is completely untested.
Update:
Given a specific date, you can find out the weekOfYear number using the weekOfYear method in the DateUtils library. Use the methods above to find the first and last date of the week in question
Conceptually like this:
var weekOfYear : Number = DateUtils.weekOfYear(myDate);
var firstDayOfWeek : Date = firstDateOfWeek(myDate);
var lastDayOfWeek : Date = lastDateOfWeek(myDate);
I dealt with this very question in this blog post. It's very simple, really. The last day of any given month is one day less than the first day of the next month. If the last day isn't a Saturday, you have an overlap.

SQLite: express the difference as days, hours, minutes between two given dates

I am trying to express the difference of two given dates in days, hours, and minutes (like 1 day, 6 hours, 17 minutes.) as SQLite query output. I have entryin and entryout as datetime fields in a SQLitedatabase. I tried all combinations of julianday and strftime but still running into rough weather.
I tried strftime('%d %H:%M', julianday(entryout)-julianday(entryin)). For a row the values are 2011-11-10 11:46, and 2011-11-09 09:00. but the output is 25 14:46 instead of 01 02:46.
Can some one help me with this, or point me correct logic for this? Thanks in advance.
You can try something like this:
SELECT
CAST((strftime('%s', '2011-11-10 11:46') - strftime('%s', '2011-11-09 09:00')) / (60 * 60 * 24) AS TEXT) || ' ' ||
CAST(((strftime('%s', '2011-11-10 11:46') - strftime('%s', '2011-11-09 09:00')) % (60 * 60 * 24)) / (60 * 60) AS TEXT) || ':' ||
CAST((((strftime('%s', '2011-11-10 11:46') - strftime('%s', '2011-11-09 09:00')) % (60 * 60 * 24)) % (60 * 60)) / 60 AS TEXT);

Resources