How to get the difference in years from two different dates?

Here’s the expression that also caters for leap years: YEAR(date1) – YEAR(date2) – (DATE_FORMAT(date1, ‘%m%d’) < DATE_FORMAT(date2, ‘%m%d’)) This works because the expression (DATE_FORMAT(date1, ‘%m%d’) < DATE_FORMAT(date2, ‘%m%d’)) is true if date1 is “earlier in the year” than date2 and because in mysql, true = 1 and false = 0, so the adjustment is simply … Read more

Remove HTML tags from record

try this solution: not tried it myself but apparently it works. source: http://forums.mysql.com/read.php?52,177343,177985#msg-177985 SET GLOBAL log_bin_trust_function_creators=1; DROP FUNCTION IF EXISTS fnStripTags; DELIMITER | CREATE FUNCTION fnStripTags( Dirty varchar(4000) ) RETURNS varchar(4000) DETERMINISTIC BEGIN DECLARE iStart, iEnd, iLength int; WHILE Locate( ‘<‘, Dirty ) > 0 And Locate( ‘>’, Dirty, Locate( ‘<‘, Dirty )) > 0 … Read more

Calculate difference between two datetimes in MySQL

USE TIMESTAMPDIFF MySQL function. For example, you can use: SELECT TIMESTAMPDIFF(SECOND, ‘2012-06-06 13:13:55’, ‘2012-06-06 15:20:18’) In your case, the third parameter of TIMSTAMPDIFF function would be the current login time (NOW()). Second parameter would be the last login time, which is already in the database.