in the databse i have the format of the date like 'yyyy-mm-dd'.
how can i fetch the current date in this format? and then if i want to calculate the date after 1 week how can i do that.
thanxx in advance. Using php and mysql.
in the databse i have the format of the date like 'yyyy-mm-dd'.
how can i fetch the current date in this format? and then if i want to calculate the date after 1 week how can i do that.
thanxx in advance. Using php and mysql.
Try CURDATE:
> SELECT CURDATE();
-> '2010-10-07'
To add 7 days use an interval:
> SELECT CURDATE() + INTERVAL 1 WEEK;
-> '2010-10-14'
You don't need to use MySQL to fetch the date if you just want to know the current date in PHP. You can use PHP's date function:
$current_date = date('Y-m-d');
If you want the date one week from now, use strtotime:
$current_date = date('Y-m-d', strtotime('+1 week'));
ref: MySQL 5.1 Reference Manual :: 11 Functions and Operators :: 11.7 Date and Time Functions using the formats defined in DATE_FORMAT
select DATE_FORMAT(NOW(),'%Y-%m-%d') as date;
or
select DATE_FORMAT(NOW() + INTERVAL 1 WEEK,'%Y-%m-%d') as date
where the INTERVAL is one of the following: mysql interval formats