Hi and Hello.
Good Day.

I have a problem in retrieving time in database. I have Table name "SAMPLE"
and have field name "DATES"


DATES
-------------------------------------|
5/9/2008 1:48:06 PM |
--------------------------------------

* If I will retrive only a date my select command is:
Select convert(nvarchar,Dates,101) as Dates from Sample

OUTPUT: Only the Date 5/9/2008.

My problem is what is the select command to retrieve only the time like the
above data.

I want the output only like this: 1:48:06 PM


Thank you in advance.

--
To be Happy is To be Yourself

Re: What is Select Command in Retrieving Time by Marc

Marc
Fri May 09 03:40:07 CDT 2008

First - this is very "off topic"; this is a SQL question, not C#.

Second - note that SQL Server 2008 ships with support for (separate)
date and time data-types, and direct casting etc - so this would be
something to consider in the future.

> * If I will retrive only a date my select command is:
> Select convert(nvarchar,Dates,101) as Dates from Sample

No; that returns a string that happens to look like the date, but which
is at high risk of i18n issues from the consuming system. Personally I'd
be tempted to worry about this at the consumer (C# code, or a report,
etc) where there is good support for date functions; however, you can do
similar in TSQL (without introducing i18n issues):

DECLARE @When datetime
SET @When = GETDATE()
SELECT @When,
CAST(CAST(@When AS int) AS datetime) AS [Date],
@When - CAST(@When AS int) AS [Time]

> I want the output only like this: 1:48:06 PM

Well, format 8 is quite similar; if you need the AM/PM then you would
probably need to trim a 0 or 100. But again; TSQL is not the best place
to format dates/times. That isn't what it is designed for.

Marc

Re: What is Select Command in Retrieving Time by Ignacio

Ignacio
Fri May 09 14:24:35 CDT 2008

On May 9, 4:17=A0am, Saimvp <Sai...@discussions.microsoft.com> wrote:
> Hi and Hello.
> Good Day.
>
> I have a problem in retrieving time in database. I have Table name "SAMPLE=
"
> and have field name "DATES"
>
> DATES
> -------------------------------------|
> 5/9/2008 1:48:06 PM =A0 =A0 =A0|
> --------------------------------------
>
> * If I will retrive only a date my select command is:
> Select convert(nvarchar,Dates,101) as Dates from Sample
>
> OUTPUT: Only the Date 5/9/2008.
>
> My problem is what is the select command to retrieve only the time like th=
e
> above data.
>
> I want the output only like this: 1:48:06 PM
>
> Thank you in advance.
>
> --
> To be Happy is To be Yourself

This is a SQL question, post it in the SQLSERVER.Developer NG