List:General Discussion« Previous MessageNext Message »
From:Mike Johnson Date:November 12 2004 5:31pm
Subject:RE: What's MYSQL equivalent to Oracle's TRUNC(date_time_var)?
View as plain text  
From: sol beach [mailto:sol.beach@stripped] 

> In Oracle TRUNC(data_time_var) returns only the date portion of a
> date_time data type.
> What's the easiest way in MYSQL to accomplish the same thing?
> I tried to RTFM  (Paul DuBios' MYSQL tome; 2nd Ed.), but no clean
> solution lept out at me.
> It is a GREAT book, but it did not help me in this case.
> 
> TIA!

Try this:

SELECT DATE_FORMAT(date_time_var, '%Y-%m-%d')

You can customize what fields you'd like in the second arg. Above will
return YYYY-MM-DD.

More here:
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html

Also, as of 4.1.1, you can use DATE(date_time_var) to return the date
portion.

HTH!


-- 
Mike Johnson             Smarter Living, Inc.
Web Developer            www.smarterliving.com
mike@stripped   (617) 886-5539

Thread
What's MYSQL equivalent to Oracle's TRUNC(date_time_var)?sol beach12 Nov
  • Re: What's MYSQL equivalent to Oracle's TRUNC(date_time_var)?Bernard Clement12 Nov
RE: What's MYSQL equivalent to Oracle's TRUNC(date_time_var)?Mike Johnson12 Nov