Re: SQL query to format datetime
From: Steve Kass (skass_at_drew.edu)
Date: 01/27/05
- Next message: oj: "Re: SQL query to format datetime"
- Previous message: oj: "Re: Unable to drop the database after dropping the republication using store procedure!!HELP !! HELP"
- In reply to: Onnuri: "SQL query to format datetime"
- Next in thread: David Buchanan: "Re: SQL query to format datetime"
- Reply: David Buchanan: "Re: SQL query to format datetime"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 26 Jan 2005 23:22:01 -0500
Onnuri,
The data is not stored with any particular format - the format
displayed when you retrieve the data may depend on the tool
you're using to query the database, on database settings, and
on regional settings of the OS.
Depending on what you want, there are two answers.
If you simply want to display 1/25/2005 when retrieving the datetime
value of January 25, 2005, 11:37:25 PM, you can select
select convert(varchar(10),getdate(),101). This will put leading
zeroes in front of date parts less than 10, which hopefully is ok.
If you want to change the actual value, and store just the date,
but not the time, you will have to change the value in your
table. You can't really store just a date, but you can store
a datetime with a time part of midnight, and it will behave like
a date-only.
update dateColumn set
dateColumn = dateadd(day,datediff(day,0,dateColumn),0)
You may also want to put a constraint on the date column
to prevent values with times other than midnight from being
entered, if this is really what you want, as opposed to just
a change in display format.
Steve Kass
Drew University
Onnuri wrote:
>Hi,
>Can I ask you a simple SQL query question? This datetime data type stores
>records like "1/25/2005 11:37:25 PM". Is there a SQL query to format it
>like "1/25/2005"? Please let me know.
>
>Onnuri
>
>
>
>
- Next message: oj: "Re: SQL query to format datetime"
- Previous message: oj: "Re: Unable to drop the database after dropping the republication using store procedure!!HELP !! HELP"
- In reply to: Onnuri: "SQL query to format datetime"
- Next in thread: David Buchanan: "Re: SQL query to format datetime"
- Reply: David Buchanan: "Re: SQL query to format datetime"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|