December 25, 2004 at 4:44 pm
i need to add one second to this
select datepart(second,Getdate())
how ??
thnks ilan
December 25, 2004 at 6:04 pm
Use DATEADD.
I cant remember the exact format, but its something like:
DATEADD(ss,1,GETDATE())
December 26, 2004 at 9:20 pm
Something like:
SELECT (datepart(s,1,getdate())
December 26, 2004 at 9:22 pm
I meant to write:
Something like:
SELECT (dateadd(s,1,getdate()))
December 27, 2004 at 1:15 am
There should be no need to use something like DATEADD. Since DATEPART returns an INTEGER you can simply do:
SELECT
DATEPART(SECOND,GETDATE())+1
to add a second.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 27, 2004 at 4:02 am
You need DateAdd; 59 seconds + 1 = 0 seconds, not 60
So this is the construction to use:
SELECT
DATEPART(SECOND,DATEADD(s,1,GETDATE()))
December 27, 2004 at 4:09 am
Actually this depends on the requirements, which haven't been stated yet.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 27, 2004 at 7:25 am
Frank is correct. The question was how to add 1 (second) to
select datepart(second,Getdate())
which returns an integer whose units are seconds. Thus,
SELECT DatePart(s, Getdate()) + 1
If the problem is how to add 1 second to the current datetime, then
SELECT DateAdd(s, 1, GetDate())
would be the expression to use.
December 27, 2004 at 10:52 am
Why do you want to do this? What are the requirements?
Here is a fun "Select"
SELECT DatePart(s, Getdate()), DatePart(s, Getdate()) + 1, GetDate(), DateAdd(s, 1, GetDate())
December 28, 2004 at 5:19 am
The max number of seconds in a minute is 59, thus adding a second to 59 should indeed be 0 (as long as you're dealing with seconds as a datetime datatype)
/Kenneth
December 28, 2004 at 5:40 am
That's right, but why would you bother to extract the seconds out of a DATETIME and add 1 if if all you really want is to add 1 second to the current time? But we can guess and guess over this requirement, the only one who can shed a light on this is the original questioner, who hasn't responded since his question.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 28, 2004 at 6:44 am
I guess that lies in the untold requirements..?
Since the poster extracted only the seconds 'counter' from the time, then you won't know the minutes. And since 59 + 1 seconds resets seconds to 0 and increments the minute by 1, this is the way it works as long as we're talking about seconds and not about primitive numbers
/Kenneth
December 28, 2004 at 6:56 am
but what if this is for some kind of duration measurement? Might sound strange, but who knows. And in that case resetting the minutes to 0 is really smart, since you can't tell how many minutes have elapsed since beginning. Questions over questions. Slow day in Sweden today?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 28, 2004 at 7:00 am
It's getting dark if nothing else.. and I'm heading for home now.. 'nuff work for this year now. See you next year
/Kenneth
December 28, 2004 at 7:02 am
Yes,I know! Your fellow swedish MVP's Erland and Tibor told me that it's getting dark around 15:00 during winter. They thought I'm crazy to even consider moving to Sweden.
Happy new year!
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 15 posts - 1 through 15 (of 19 total)
You must be logged in to reply to this topic. Login to reply