MySQL – DATE_ADD month interval

DATE_ADD works just fine with different months. The problem is that you are adding six months to 2001-01-01 and July 1st is supposed to be there. This is what you want to do: SELECT * FROM mydb WHERE creationdate BETWEEN “2011-01-01” AND DATE_ADD(“2011-01-01”, INTERVAL 6 MONTH) – INTERVAL 1 DAY GROUP BY MONTH(creationdate) OR SELECT … Read more

How to select last one week data from today’s date

Yes, the syntax is accurate and it should be fine. Here is the SQL Fiddle Demo I created for your particular case create table sample2 ( id int primary key, created_date date, data varchar(10) ) insert into sample2 values (1,’2012-01-01′,’testing’); And here is how to select the data SELECT Created_Date FROM sample2 WHERE Created_Date >= … Read more

Subtract minute from DateTime in SQL Server 2005

SELECT DATEADD(minute, -15, ‘2000-01-01 08:30:00′); The second value (-15 in this case) must be numeric (i.e. not a string like ’00:15′). If you need to subtract hours and minutes I would recommend splitting the string on the : to get the hours and minutes and subtracting using something like SELECT DATEADD(minute, -60 * @h – … Read more

Add ‘x’ number of hours to date

You may use something like the strtotime() function to add something to the current timestamp. $new_time = date(“Y-m-d H:i:s”, strtotime(‘+5 hours’)). If you need variables in the function, you must use double quotes then like strtotime(“+{$hours} hours”), however better you use strtotime(sprintf(“+%d hours”, $hours)) then.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)