Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2006, 11:48 PM
Registered User
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datetime to Date during Query

I'm using mysql for my db.

I have a question here but i'm not with putting it into proper sentences, so here's the example of what i wanna do.

table: TableA
field: myDatetime >>> datatype: datetime

is it possible to query this table but with the myDatetime field displayed as "yyyy-MM-dd" instead of the datetime format
"yyyy-MM-dd hh:mm:ss"?

Thanks people.

 
Old April 4th, 2006, 11:59 PM
Authorized User
 
Join Date: Mar 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Krashed

Here is your solution...

The table is
mysql> desc mytab;
+------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| mydatetime | datetime | YES | | NULL | |
+------------+----------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> select * from mytab;
+---------------------+
| mydatetime |
+---------------------+
| 2006-04-05 10:22:15 |
+---------------------+
1 row in set (0.03 sec)


mysql> select date_format(mydatetime,'%Y-%m-%d') from mytab;
+------------------------------------+
| date_format(mydatetime,'%Y-%m-%d') |
+------------------------------------+
| 2006-04-05 |
+------------------------------------+
1 row in set (0.00 sec)

Best Regards
Milind






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need ONLY date in datetime field in Database Lucy SQL Server 2000 10 April 30th, 2007 09:20 AM
DATE from DATETIME latha Classic ASP Databases 2 May 30th, 2006 11:02 AM
Compare only the date portion of a datetime field CricketMaster Access 6 April 27th, 2005 01:06 AM
Seperating Date part from a datetime field ctranjith SQL Server 2000 2 October 25th, 2004 06:42 AM
Getting Date part out of Datetime in Stored Pr pavel SQL Server 2000 3 February 18th, 2004 04:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.