Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2004, 10:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Naperville, IL, USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default Convert DateTime

What is the easiest way to extract only the date from a datetime field?
I want to be able to group by a date in a datetime field and ignore the time part.

I've tried to use left(datetime, 11) but it reformats the date as MMMM dd ccyy (the original format was mm/dd/ccyy). To be honest, the format that I would prefer is either ccyy/mm/dd or ccyy.mm.dd.

Do I need to write a function to get this date format?

Rand
__________________
Rand
Reply With Quote
  #2 (permalink)  
Old October 4th, 2004, 10:56 AM
Authorized User
 
Join Date: Jul 2004
Location: cleveland, oh, USA.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I created a function to convert my AS400 DB2 dates,

CREATE FUNCTION [ufn_AS400Date] (@InDate datetime)
RETURNS varchar(10) AS
BEGIN
    RETURN LEFT(CONVERT(VarChar(20), @InDate, 120), 10)
END

Check out the Convert function in BOL.


David


Reply With Quote
  #3 (permalink)  
Old October 4th, 2004, 12:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Naperville, IL, USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

It does exactly what is needed!

:D

Rand
Reply With Quote
  #4 (permalink)  
Old October 5th, 2004, 09:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use this instead.
Code:
CONVERT(VarChar(10), getdate(), 120)
without having to extract the 10 characters from the left, after conversion.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert String to DateTime SimoNWellborne C# 3 October 11th, 2014 02:24 AM
Convert DateTime Format dnyanubhamare C# 2005 2 February 25th, 2008 09:06 AM
How to convert a datetime into a binary... gbianchi SQL Language 2 September 10th, 2007 09:43 AM
How to convert a string in DateTime elena SQL Language 6 March 29th, 2006 06:59 PM
How to convert a string in DateTime elena ADO.NET 3 July 24th, 2003 04:31 PM



All times are GMT -4. The time now is 04:46 AM.


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