Tiya
Tiya

Reputation: 321

fetching the current date in sql

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.

Upvotes: 1

Views: 377

Answers (3)

Richard Harrison
Richard Harrison

Reputation: 19393

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

Upvotes: 1

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124758

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'));

Upvotes: 1

Mark Byers
Mark Byers

Reputation: 837926

Try CURDATE:

> SELECT CURDATE();
-> '2010-10-07'

To add 7 days use an interval:

> SELECT CURDATE() + INTERVAL 1 WEEK;
-> '2010-10-14'

Upvotes: 4

Related Questions