General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 14th, 2004, 05:15 PM
RHerbert RHerbert is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 RHerbert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Converting DateTime to Date

I am new to SQL Language. I would like to know if there is a function that will return only the date from a DateTime field? I noticed that the date in the SQL database is reversed. Example 2004-04-14 09:57:17.000. I would like the date only return when I execute a SQL Query like 04/14/2004.
Is this possible? If so, can someone help?

Thanks

Greatly appreciated.

Herb

Reply With Quote
  #2  
Old August 10th, 2004, 08:33 AM
varkey varkey is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 varkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try this

even i was searching for tat .this works
select REPLACE(CONVERT(VARCHAR,Date_Field,3),'/','/') from Table_Name
it gives the results in dd/mm/yy format try changing the 3rd parameter in the convert() to get different formats

Reply With Quote
  #3  
Old August 10th, 2004, 08:43 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to dhouston
If you're using mysql, the DATE_FORMAT() function is also an option.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #4  
Old November 9th, 2004, 02:24 PM
Makito Makito is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 Makito User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Answer

select col1, col2
From thisTable
WHERE convert (datetime, convert (varchar, datecol, 101), 101) = @yourdate

Reply With Quote
  #5  
Old May 4th, 2010, 05:49 AM
dragonbb dragonbb is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2010
Posts: 1 dragonbb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 31 sec
Reputation Power: 0
try "Cast(opentime as date) , the opentime is a datetime variable. cheers

Reply With Quote
  #6  
Old June 15th, 2010, 11:47 PM
praveenbattula praveenbattula is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 1 praveenbattula User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 52 sec
Reputation Power: 0
Convert date time to date

This is the good way of doing it.
DATEADD(dd,(DATEDIFF(dd,0,DateSent)),0)
Do not use Convert or CAST to find the date from date time field. That is not efficient and not recommended because of some performance problems.

And if you need this date for comparison operation then this is the exact post you need to look at.

praveenbattula.blogspot.com/2010/06/compare-date-only-in-datetime-field-in.html

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Converting DateTime to Date


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap