Operations with dates - cakephp

I need to check if is missing 10 days or less to arrive at a certain date.
I'm trying this:
if(date('d/m/Y') >= CakeTime::format('d/m/Y','30/04/2013','-10 days', true )) {
but apparently the Caketime::format is not working correctly.
Any help, pls?

CakePHP doesn't prevent you from using regular PHP functionality. If PHP itself already offers what you're looking for, it is even prefered.
In PHP, you can calculate the difference between two dates using DateTime::diff()
A quick search on StackOverflow gave me this question, which contains proper examples:
Date Difference in php on days?

Related

parseISO in date-fns showing the incorrect date

I'm attempting to understand what exactly date-fns is doing when using parseISO() as it seems to be adding 2 hours to the time that I have saved in the database. The data is as follows:
ISO Date/Time saved in database: 2022-09-20T19:52:53.000Z
Using format(parseISO(2022-09-20T19:52:53.000Z), "HH:mm:ss") I get this: 21:52:53 hrs
Somewhere along the line 2 hours are being added and unsure as to the cause. A comment left by Monash Joshi in (stackoverflow issue) hints towards an explanation but not really a solution. Want I want to show is just the parsed date/time value as it is. Would it thus make sense to manipulate the string that I receive from the database myself?
Thanks in advance for your help! And let me know if you need any further information.

Solr - Date Query

I am relatively new to Solr and I am trying to achieve the following: get all records where a certain field matches the current date (e.g. 16/04/2021 00:00 to 16/04/2021 23:59).
I have looked at the docs, but there aren't many examples.
Could someone please point me in the right direction?
Thanks
Based on information in the Working with dates section of the reference guide:
datefield:[2021-04-16T00:00:00Z TO 2021-04-17T00:00:00Z}
The } and the end indicates "not inclusive", so everything up to, but not actually inside the next day. You could use .. TO 2021-04-16T23:59:59.999Z] or something similar as well, but it's probably better to be explicit.

Using CAST or CONVERT inside a view MSSQL

Hi Having a syntax issue - at least I think it is. I want a default date as part of a case statement inside a materialised view (MS SQL 2008 +):
, CASE
WHEN WithFirstDate = 0 THEN CONVERT(DATE,'1900-JAN-1', 101)
WHEN WithFirstDate = 1 THEN
Start1
ELSE --WithFirstDate = 2
Start2
END ValidDate
I'm getting the following error:
view uses an implicit conversion from string to datetime or smalldatetime. Use an explicit CONVERT with a deterministic style value
I'd like to have a solution that works irrespective of localization (i.e US style dates, Japanese style dates and the rest of the world)
Thanks
Instead of:
CONVERT(DATE,'1900-JAN-1', 101)
Just do:
CONVERT(DATE,'1900-01-01')
However the issue may be with the other two columns, Start1 and Start2. I am guessing these are not DATE columns.
The 101 code you are passing the CONVERT function does not match your format. Check the following link to find the correct code:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Ok well this forum has gone downhill IMHO, first my post get endless edited for grammar which doesn't change the meaning, then it gets voted down presumably because it was "to difficult" to answer. https://stackoverflow.com/users/61305/aaron-bertrand was on the right lines. Thanks Aaron. The problem was a computed column in one of the referenced tables was non deterministic. This error only resolved in a flag when the materialising clustered index was being created on the view. I'd post a link to the full answer but not allowed. Shame I cant recover all my old badges and points from a couple of years ago. Full answer here http://tinyurl.com/knor8qk

Bugzilla - Can I see what I did yesterday?

I'm running Bugzilla 4.2.5. I would like to save a search to see what I worked on yesterday - so anything that I recorded any time against, or updated the comments for.
I'm hoping that I can then use the output to help with my daily scrum question "what did you do yesterday?"
When I go into search -> Advanced Search, I can see a "Search by change history" section which looks exactly like what I'd like to use.
So to test it, I've recorded one hour on a bug assigned to me. I want to be able to find that bug as changed in the last day.
So I go to the "Change history" section, select the field "Hours worked" - (is there a wildcard I can put in changed to?) In any case I know it has transitioned from zero to 1 hours, so I'll enter "1" into that field.
Next comes the dates, where it says I can enter YYYY-MM-DD or relative dates. How do I do a relative date for changed between yesterday and today...? In any case I'll look between 2013-01-01 and 2013-12-31.
It brings back Zarro Boogs Found. So what am I doing wrong with the search, I know that I've just changed a bug I'm working on and set one hour of time to it.
I'm hoping someone can help, I've had a good search around for documentation and tried for hours to get this working! Thanks!
Aha, I've found it,
Advanced search, Custom search, "Hours worked" -> "Changed after" -> "1d"
Thanks! :)

CakePHP Form Helper minYear

I need to generate a year drop down with cake to populate ArchiveQuarter.year in the database. This is currently set in the database to 'year', but it was producing the same results with 'date'.
This is the current setup:
echo $this->Form->input('ArchiveQuarter.year', array(
'label'=>'Year',
'type'=>'date',
'dateFormat'=>'Y',
'minYear'=>'2000',
'maxYear'=>date('Y'),
));
The problem is that this produces a dropdown with a range of 1970-2013 instead of 2000-2013. The minYear does work though, because if you set it below 1970 then it will indeed work.
I literally copied and pasted your code into my CakePHP 2.3.0 app, and it worked as expected - gave me a select input from 2013 to 2000.
Maybe try getting the most recent version of CakePHP (your question doesn't list what version you're using) and try that?
Bottom line, the code you've provided does work - so if it's not for you, there are other factors in play.
I did some research into what was going on within the FormHelper.php file and here is a breakdown:
In the dateTime() function it checks if $attributes['value'] is empty. If it is it fills that information using $this->value($attributes,$fieldName); populating it with 2013
2013 is then parsed by _GetDateTimeValue()
Within _GetDateTimeValue() it is parsed as numeric, and is translated from unix time; an hour and a half into 1970.
That then is set as the value of the final select box, which has to expand from the minYear to properly accommodate.
For whatever reason Cake does not take into account the explicitely stated dateFormat=>'Y' when is parses with _GetDateTimeValue().
The solution is to insert: $selected => strtotime('now') which will in the end get properly parsed.
You can also explicitly set $selected to values outside of the range of dates, which I'm not sure would be a wanted before or not.

Resources