Ignore Negative Values in MySQL DATEDIFF Function

radhakrishna
Updated on 29-Jan-2020 06:39:03

1K+ Views

As we know that DATEDIFF() function is used to get the difference in a number of days between two dates. Hence, it is quite possible that it returns negative value as well.mysql> select * from differ; +------------+-------------+ | OrderDate  | WorkingDate | +------------+-------------+ | 2017-10-22 | 2017-10-29  | | 2017-10-25 | 2017-10-30  | | 2017-10-25 | 2017-11-30  | +------------+-------------+ 3 rows in set (0.00 sec)Above query will return the values from table ‘differ’. Now, if someone wants to get the difference between OrderDate and WorkingDate then the output would be negative as follows −mysql> Select DATEDIFF(OrderDate, WorkingDate)AS 'DIFFERENCE IN DAYS' ... Read More

Play Video on Canvas and Preserve Last Frame Image on HTML5 Canvas

Lakshmi Srinivas
Updated on 29-Jan-2020 06:38:07

305 Views

You can try to run the following code to play and preserve the video’s last frame:var c = $('canvas')[0]; var context = canvas.getContext('2d'); c.width = 640; c.height = 480; $("#,myPlayer").on('play', function (e) {    var $this = this;    (function loop() {       if (!$this.paused && !$this.ended) {          context.drawImage($this, 0, 0, 640, 480);          setTimeout(loop, 1000 / 30);       }    })(); });

Calculate Difference in Years, Months, and Days Between Two Dates

vanithasree
Updated on 29-Jan-2020 06:37:59

116 Views

We can create a function, which accepts the date values as its argument and returns the difference in year, month and days, as followsmysql> CREATE FUNCTION date_difference(Date1 DATE, date2 DATE) RETURNS VARCHAR(30)    -> RETURN CONCAT(    -> @years := TIMESTAMPDIFF(YEAR, date1, date2), IF (@years = 1, ' year, ', ' years, '),    -> @months := TIMESTAMPDIFF(MONTH, DATE_ADD(date1, INTERVAL @years YEAR), date2), IF (@months = 1, ' month, ', ' months, '),    -> @days := TIMESTAMPDIFF(DAY, DATE_ADD(date1, INTERVAL @years * 12 + @months MONTH), date2), IF (@days = 1, ' day', ' days')) ;    Query OK, 0 ... Read More

Retrofit Existing Web Page with Mobile CSS

karthikeya Boyini
Updated on 29-Jan-2020 06:37:40

158 Views

To retrofit, use the CSS media queries, and allow different stylesheets to different browser capabilities. A benefit is that you do not have to go for any server-side code.This would require you to add specific detection code to the script for grouping of the device.The media queries handle even devices you've never heard of.Set the following:@media handheld and (max-width: 480px), screen and (max-device-width: 480px), screen and (max-width: 600px) {    body {       color: blue;    } }

Fetch All Records from a MySQL Table

Alankritha Ammu
Updated on 29-Jan-2020 06:37:09

291 Views

We can fetch all the record from a MySQL table by using SELECT * from table_name; query. An example is as follows, fetched all the records from ‘Employee’ table −mysql> Select * from Employee; +------+--------+ | Id   | Name   | +------+--------+ | 100  | Ram    | | 200  | Gaurav | | 300  | Mohan  | +------+--------+ 3 rows in set (0.00 sec)

Frame-by-Frame Animation in HTML5 with Canvas

Nishtha Thakur
Updated on 29-Jan-2020 06:36:50

776 Views

To create a frame by frame animation in HTML5 with canvas, try to run the following code:var myImageNum = 1; var lastImage = 5; var context = canvas.getContext('2d'); var img = new Image; img.onload = function(){    context.clearRect( 0, 0, context.canvas.width, context.canvas.height );    context.drawImage( img, 0, 0 ); }; var timer = setInterval( function(){    if (myImageNum > lastImage){       clearInterval( timer );    }else{       img.src = "images/left_hnd_"+( myImageNum++ )+".png";    } }, 1000/15 );

Different Ways to Add Half-Year Interval in MySQL Date

seetha
Updated on 29-Jan-2020 06:36:20

602 Views

We can add ‘half year interval’ in date ith the following ways −(A) By adding interval of 6 Monthsmysql> Select '2017-06-20' + INTERVAL 6 Month AS 'After Half Year Interval'; +--------------------------+ | After Half Year Interval | +--------------------------+ |  2017-12-20              | +--------------------------+ 1 row in set (0.00 sec)(B) By adding interval of 2 quartersmysql> Select '2017-06-20' + INTERVAL 2 Quarter AS 'After Half Year Interval'; +--------------------------+ | After Half Year Interval | +--------------------------+ | 2017-12-20               | +--------------------------+ 1 row in set (0.00 sec)Above query will add half year interval in date with the help of Quarter keyword.

Test if the HTML Attribute tabindex is Present and Get the Value

Nitya Raut
Updated on 29-Jan-2020 06:35:53

498 Views

To get the value of the HTML attribute, try the following:$("#demo").attr("tabindex")The attr() method can be used to either fetch the value of an attribute from the first element in the matched set or set attribute values onto all matched elements.You can also use the hasAttribute() method to see if there is an attribute for an element.ExampleTry to run the following code to learn how to use hasAttribute() method:                          $(document).ready(function(){             $('button').on('click', function() {                if (this.hasAttribute("style")) {                   alert('True')                } else {                   alert('False')                }             })          });                              Button                      Button 2          

Blank PNG Image Shown with toBase64Image Function

Samual Sam
Updated on 29-Jan-2020 06:35:13

254 Views

If a blank image is shown with the toBase64Image() function, you need to use the following to work on it correctly:animation: {    duration: 2000,    onComplete: function (animation) {       this.toBase64Image();    } }With that, you can also use another fix. Call save64Img(myChart.toBase64Image()) over an additional callback and set it like this:myLine = {    onAnimationComplete: function () {       save64Img(myChart.toBase64Image());    } }

Add 3 Months Interval to MySQL Date Without Using the Word Months

Nishtha Thakur
Updated on 29-Jan-2020 06:35:05

412 Views

It is possible with the help of keyword Quarter as follows −mysql> Select '2017-06-20' + INTERVAL 1 Quarter AS 'After 3 Months Interval'; +-------------------------+ | After 3 Months Interval | +-------------------------+ | 2017-09-20              | +-------------------------+ 1 row in set (0.00 sec)

Advertisements