Posts

Showing posts with the label Date

CakePHP Find Condition For A Query Between Two Dates

Answer : $conditions = array( 'conditions' => array( 'and' => array( array('Item.date_start <= ' => $date, 'Item.date_end >= ' => $date ), 'Item.title LIKE' => "%$title%", 'Item.status_id =' => '1' ))); Try the above code and ask if it not worked for you. Edit: As per @Aryan request, if we have to find users registered between 1 month: $start_date = '2013-05-26'; //should be in YYYY-MM-DD format $this->User->find('all', array('conditions' => array('User.reg_date BETWEEN '.$start_date.' AND DATE_ADD('.$start_date.', INTERVAL 30 DAY)'))); Here is CakePHP BETWEEN query example. I'm defining my arrays as variables, and then using those variables in my CakePHP find function call: // just return...

Adding Days To $Date In PHP

Answer : All you have to do is use days instead of day like this: <?php $Date = "2010-09-17"; echo date('Y-m-d', strtotime($Date. ' + 1 days')); echo date('Y-m-d', strtotime($Date. ' + 2 days')); ?> And it outputs correctly: 2010-09-18 2010-09-19 If you're using PHP 5.3, you can use a DateTime object and its add method: $Date1 = '2010-09-17'; $date = new DateTime($Date1); $date->add(new DateInterval('P1D')); // P1D means a period of 1 day $Date2 = $date->format('Y-m-d'); Take a look at the DateInterval constructor manual page to see how to construct other periods to add to your date (2 days would be 'P2D' , 3 would be 'P3D' , and so on). Without PHP 5.3, you should be able to use strtotime the way you did it (I've tested it and it works in both 5.1.6 and 5.2.10): $Date1 = '2010-09-17'; $Date2 = date('Y-m-d', strtotime($Date1 . " + 1 day...

Can I Use An HTML Input Type "date" To Collect Only A Year?

Answer : No you can not but you may want to use input type number as a workaround. Look at the following example: <input type="number" min="1900" max="2099" step="1" value="2016" /> No, you can't, it doesn't support only year, so to do that you need a script, like jQuery or the webshim link you have, which shows year only. If jQuery would be an option, here is one, borrowed from Sibu: Javascript $(function() { $( "#datepicker" ).datepicker({dateFormat: 'yy'}); });​ CSS .ui-datepicker-calendar { display: none; } Src: https://stackoverflow.com/a/13528855/2827823 Src fiddle: http://jsfiddle.net/vW8zc/ Here is an updated fiddle, without the month and prev/next buttons If bootstrap is an option, check this link, they have a layout how you want. There is input type month in HTML5 which allows to select month and year. Month selector works with autocomplete. Check the examp...

Best Approach To Remove Time Part Of Datetime In SQL Server

Answer : Strictly, method a is the least resource intensive: a) select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) Proven less CPU intensive for the same total duration a million rows by someone with way too much time on their hands: Most efficient way in SQL Server to get a date from date+time? I saw a similar test elsewhere with similar results too. I prefer the DATEADD/DATEDIFF because: varchar is subject to language/dateformat issues Example: Why is my CASE expression non-deterministic? float relies on internal storage it extends to work out first day of month, tomorrow, etc by changing "0" base Edit, Oct 2011 For SQL Server 2008+, you can CAST to date i.e. CAST(getdate() AS date) . Or just use date datatype so no time to remove. Edit, Jan 2012 A worked example of how flexible this is: Need to calculate by rounded time or date figure in sql server Edit, May 2012 Do not use this in WHERE clauses and the like without thinking: adding a function or CAST...

Automatically Convert Date Text To Correct Date Format Using Google Sheets

Image
Answer : The , at portion of the string is keeping Google Sheets from recognizing it as a datevalue. Just remove it with the substitute function and wrap in datevalue function like so: =DATEVALUE(SUBSTITUTE(A1,", at","")) To format as DD/MM/YYYY just go to custom formatting and set it to look like the following: =DATEVALUE(JOIN("/", LEFT(D5,2), {MID(D5,4,2), RIGHT(D5,4)})) where D5 contains for example: 25.06.2019 which script converts to datevalue: 43641 Dateformat is as dd.MM.YYYY converted to dd/MM/YYYY and then converted to datevalue. Google sheet's documentation helps: DATEVALUE , JOIN , LEFT , MID , RIGHT Datevalue is useful for organizing rows of data by date correctly. Another solution is to create custom function. Open tools → script editor in menu to open script editor in new tab Click Untitled project in top left corner and rename Open Resources → Libraries in top menu Paste library key MHMchiX6c1bwSqGM1PZiW_Pxh...

AngularJS - Convert Dates In Controller

Answer : item.date = $filter('date')(item.date, "dd/MM/yyyy"); // for conversion to string http://docs.angularjs.org/api/ng.filter:date But if you are using HTML5 type="date" then the ISO format yyyy-MM-dd MUST be used. item.dateAsString = $filter('date')(item.date, "yyyy-MM-dd"); // for type="date" binding <input type="date" ng-model="item.dateAsString" value="{{ item.dateAsString }}" pattern="dd/MM/YYYY"/> http://www.w3.org/TR/html-markup/input.date.html NOTE: use of pattern="" with type="date" looks non-standard, but it appears to work in the expected way in Chrome 31. create a filter.js and you can make this as reusable angular.module('yourmodule').filter('date', function($filter) { return function(input) { if(input == null){ return ""; } var _date = $filter('date')(new Date(input), ...