Check the expire date of every rows - cakephp

I'll try to explain my problem:
I have one model Attorney with have many rows.
Every attorney have a date to expire in a date coloumn. Ex: 15/09/2013
I need to check, every day, if some attorney will expire in 30 days.
In other words, I need to check, every day, the date of every attorney registered and if the date of expire is less than 30 days, and grab the id of the attorney in this situation and execute an action.
I have nothing. How I do this?

You will probably need to use a cron job to execute these task every day.
To check if a record will expire in 30 days, you could use php strtotime to calc the final date. Then, you should compare if the expire date is lower or equals:
date('Y-m-d', strtotime( date('Y-m-d') . ' +30 day' ));

try the cron job for linux ;or schedule for windows . they will check the date field and do an action depend on your conditions , here is a link for example :
http://blog.nexcess.net/2013/05/09/cron-job-for-the-last-day-of-the-month/

Related

Cron Script to execute a job every 14 days from a given date in specific time zone

I want to execute a Job in CRON for every 14 days from a specific date and timezone.
As an e.g. from JUNE 24TH every 14 days in CST time zone.
Run job every fortnight
The easy way
The easiest way to do this is simply to create the task to run every 14 days from when you want it to first run like:
CREATE TASK mytask_fortnightly
WAREHOUSE = general
SCHEDULE = '20160 MINUTE'
AS
SELECT 'Hello world'
How it works
As there are 60 minutes in an hour, 24 hours in a day and 14 days in a fortnight, ergo that's 20,160 minutes.
Caveat
The above solution does not run the task every fortnight from a given date/time, but rather every fortnight from when the task is created.
Even though this is the simplest method, it does require you to be nominally present to create the task at the exact desired next scheduled time.
As a workaround however, you can create a one-shot task to do that for you the very first time at the exact correct date/time. This means you don't have to remember to be awake / alert / present to do it manually yourself, and you can clean up the creation task afterwards.
The harder way.
Other solutions will require you to create a task which gets run every Thursday (since 2021-06-24 is/was a Thursday, each subsequent Thursday will either be the off-week, or the fortnight week)
e.g. SCHEDULE = 'USING CRON 0 0 * * THU'
Then you will add specific logic to it to determine which one the correct fortnight is.
Using this method will also incur execution cost for the off-week as well to determine if it's the correct week.
Javascript SP
In javascript you can determine if it's the correct week or not by subtracting the start date from the current date and if it's not a mutiple of 14 days, use this as a conditional to short circuit the SP.
const deltaMs = (new Date) - (new Date('2021-06-24'));
const deltaDays = ~~(deltaMs / 86400000);
const run = deltaDays % 14 === 0;
if (!run) return;
// ... continue to do what you want.
SQL
You can also check if it's a fortnight using the following SQL condition in a WHERE clause, or IFF / CASE functions.
DATEDIFF('day', '2021-06-24', CURRENT_DATE) % 14 = 0

Google Application Engine Run cron job

How I can set GAE cron job to run at specific date at specific time
Like 10th April at 12:20 minute.Please provide syntax for this use case.
How to set IST time zone.
From the cron format documentation:
If you want more specific timing, you can specify the schedule as:
("every"|ordinal) (days) ["of" (monthspec)] (time)
Where:
ordinal specifies a comma separated list of "1st", "first" and so
forth (both forms are ok) days specifies a comma separated list of
days of the week (for example, "mon", "tuesday", with both short and
long forms being accepted); "every day" is equivalent to "every
mon,tue,wed,thu,fri,sat,sun" monthspec specifies a comma separated
list of month names (for example, "jan", "march", "sep"). If omitted,
implies every month. You can also say "month" to mean every month, as
in "1,8,15,22 of month 09:00". time specifies the time of day, as
HH:MM in 24 hour time.
So you'd want something like:
schedule: 10 of april 12:20
timezone: Asia/Kolkata
Possible solutions:
1) Create a cronjob that runs once a minute. When the current time equals your desired time, run your code.
2) If the specific time is in the next 30 days, use a Task with the eta property set: https://developers.google.com/appengine/docs/python/taskqueue/tasks#Task
3) Use some external service to setup a webhook that gets called at the proper time, make your code run when the webhook is called.

Calculate Facebook likes, comments, and shares for different time zones from saved UTC

I've been struggle with this for a while and hope someone can give me an idea to tackle this.
We have a service that goes out and collects Facebook likes, comments, and shares for each status update multiple times a day. The table that stores this data is something like this:
PostId EngagementTypeId Value CollectedDate
100 1(for likes) 10 1/1/2013 1:00
100 2 (comments) 2 1/1/2013 1:00
100 3 0. 1/1/2013 1:00
100. 1. 12 1/1/2013 3:00
100. 2. 3. 1/1/2013 3:00
100. 3 5. 1/1/2013 3:00
Value holds the total for each engagement type at the time of collection.
I got a requirement to create a report that shows new value per day at different time zones.
Currently,I'm doing the calculation in a stored procedure that takes in a time zone offset and based on that I calculate the delta for each day. If this is for someone in California, the report will show 12 likes, 3 comments, and 5 shares for 12/31/2012. But if someone with the time zone offset of -1, he will see 10 likes on 12/31/2012 and 2 likes on 1/1/2013.
The problem I'm having is doing the calculation on the fly can be slow if we have a lot of data and a big date range. We're talking about having the delta pre-calculated for each day and stored in a table and I can just query from that ( we're considering SSAS but that's for the next phase). But doing this, I would need to have the data for each day for 24 time zones. Am I correct (and if so, this is not ideal) or is there a better way to approach this?
I'm using SQL 2012.
Thank you!
You need to convert UTC DateTime stored in your column to Date based on users UTC time. This way you don't have to worry about any table that has to be populated with data. To get users date from your UTC column you will use something like this
SELECT CONVERT(DATE,(DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), GETDATE()), '01/29/2014 04:00')))
AS MyLocalDate
The select statement above figures out Local date based on the difference of UTC date and local Date. You will need to replace GETDATE() with users DATETIME that is passed in to your procedure and replace '01/29/2014 04:00' with your column. This way when you select any date from your table it will be according to what that date was at users local time. Than you can calculate other fields accordingly.

What time zone does a scheduled job use for Preferred Start Time

We have a scheduled job that runs on the 1st of each month with a Preferred Start Time of 1am. The job was scheduled using the Salesforce interface (Develop | Apex Classes | Schedule Apex). When it runs, it sets a month field for records based on the System date (System.today();). Occasionally, the month is set wrongly, and I suspect it's due to the date variable set to the System date.
If I set the job to run at 1am, logged in as my User (with a time-zone set to CDT), using the interface, what value would be returned by System.today()? Would the current CDT date be returned, or the GMT date?
Scheduled jobs run as "system", but I think there's still a user context, which means Date.today() or System.today() would be in CDT.
Update:
Just tested this and DateTime.now() returns GMT values.
Another update:
The docs say Date.today() returns the date in the current user's time zone. Based on the test below, the system knows who the user is, and it knows the user's time zone, so Date.today() would be the current date in the user's time zone. I confirmed this by setting my time zone to +10, and the system returned 2012-03-15 for the date.
// Brisbane +10 time zone
global void execute(SchedulableContext SC) {
System.debug(DateTime.now()); // 2012-03-14 19:24:39
System.debug(DateTime.now().formatLong()); // 3/15/2012 5:24:39 AM AEST
System.debug(Date.today()); // 2012-03-15 00:00:00
System.debug(UserInfo.getUserName()); // dev1#jeremyross.org
}
From the APEX dev guide:
The System.Schedule method uses the user's timezone for the basis of all schedules.

how to get diff b/w 2 columns which is in time format

I've 2 columns called record time and unload time which is in time format AM/PM and I require a new column called total time where I need to find difference between unload time and record time...
for example here is my table
record time unload time
11:37:05 PM 11:39:09 PM
11:44:56 PM 1:7:23 AM
For this I require a new column which finds the difference between these 2 columns.
Cab anyone suggest a query for this please?
why you cant go with datediff system function in SQL SERVER
select datediff(mi,'11:37:05 PM','11:39:09 PM')
mi/n is for minute
If you're doing timespan calculations within one 24 hour period, anishmarokey's response is correct. However, I'd add the date to the time field as well, if you're going to have cases where the load and unload might occur over midnight between two or more days.

Resources