Thursday, 14 August 2014

how to set unique for combined columns in mysql

ALTER TABLE `tablename` ADD UNIQUE `unique_index`(`column1`, `column2`, `column2`);

Saturday, 7 June 2014

how to calculate the difference between two datetimes in seconds with mysql

This is the simplest format of finding datetime difference in Minutes

select  TIMESTAMPDIFF(
SECOND , '2013-10-19 10:42:53',  '2013-10-19 10:43:53' ) AS minutes from table name


 If u  want to give the column names to find datetime diference.....

select  TIMESTAMPDIFF(
SECOND , colname1,  colname2 ) AS minutes from table name

how to calculate the difference between two datetimes in hours with mysql

This is the simplest format of finding datetime difference in Minutes

select  TIMESTAMPDIFF(
HOUR, '2013-10-19 10:42:53',  '2013-10-19 10:43:53' ) AS minutes from table name


 If u  want to give the column names to find datetime diference.....

select  TIMESTAMPDIFF(
HOUR, colname1,  colname2 ) AS minutes from table name

how to calculate the difference between two datetimes in minutes with mysql

This is the simplest format of finding datetime difference in Minutes

select  TIMESTAMPDIFF(
MINUTE , '2013-10-19 10:42:53',  '2013-10-19 10:43:53' ) AS minutes from table name


 If u  want to give the column names to find datetime diference.....

select  TIMESTAMPDIFF(
MINUTE , colname1,  colname2 ) AS minutes from table name

Monday, 5 May 2014

Adding n days from current datetime



<?php

            $x=3;
            $valid=date('Y-m-d H:i:s', time() + $x*(24 * 60 * 60));
?>


              $x is the variable where we can give the number of days that has to be incremented from the current datetime......