Home about IT Motivation Course Sales Project About Me

Monday, June 11, 2012

script to create date range in MySQL


below quer to create date range in mysql.
usually used for create working calender for employee attendance
 
 
 
DROP PROCEDURE IF EXISTS datespopulate;

DELIMITER |

CREATE PROCEDURE datespopulate(dateStart DATE, dateEnd DATE)

BEGIN

  WHILE dateStart <= dateEnd DO

    INSERT INTO datetable (d) VALUES (dateStart);

    SET dateStart = date_add(dateStart, INTERVAL 1 DAY);

  END WHILE;

END;

|

DELIMITER ;

CALL datespopulate('2010-11-01','2015-01-01');
 
Note I named my table "datetable" and the column is named "d", but feel free to change this. Works fine on my end, let me know if you run in to an issue.

 source from : http://stackoverflow.com/questions/4736690/create-mysql-date-range

timezone mysql & PHP not correct

To see what timezone your MySQL session is using, just execute this:
SELECT @@global.time_zone, @@session.time_zone;

to changes timezone, run below script: use super previlage
mysql> SET GLOBAL time_zone = 'America/New_York';
 or 
mysql> SET GLOBAL time_zone = 'Asia/Krasnoyarsk'; 
 
to check your date correct, use this:
select date(now());
or 
select curdate();
 
for php, please go to php.ini then edit below:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "America/Los_Angeles"

; http://php.net/date.default-latitude
;date.default_latitude = 31.7667 
 
changes : America/Los_Angeles --> Asia/Seoul