Thursday, March 22, 2012
DateTimestamp
I currently have a column in a table that is a default of getdate()). My
question : Is there a way to capture just the date without the time appended
?
For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexes
on this datetimestamp field? Would a clustered index on this field help?
Almost all searching is done by the date field, whether it is searched by da
y
or a date range...Any better way than what is currently being done to help
with speed ? Currently we have a clustered index on this column. The column
currently contains approximately 12 million rows...
Thanks for your input,
WarrenChange the defualt to Cast (getdate() as Integer)
-- Datetimes as stored internally as a decimal value 4 bytes for the
integer portion, and another 4 bytes for the fractional portion. The 4 byte
s
for integer portion are the date, and the other 4 bytes are the time... So i
f
you cast the value to an integer, you truncate the time...
"Warren" wrote:
> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||Store same time for all rows.
Example:
use tempdb
go
create table dbo.t (
colA int not null identity unique,
colB datetime default (convert(char(8), getdate(), 112))
)
insert into t default values
WAITFOR DELAY '00:00:00.999'
insert into t default values
WAITFOR DELAY '00:00:00.999'
insert into t default values
select * from t
drop table t
go
If you are planning to do a lot of selects filtering this column based on a
range of dates, then having a clustered index by this column will be helpful
.
AMB
"Warren" wrote:
> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||There is no way to capture a date without the time portion; best thing to do
is probably write a function that sets each portion of the time to zero - us
e
DATEDIFF and DATEADD functions to subtract hours, minutes, seconds, and
milliseconds from the date.
With SQL 2000 32-bit datetimes are stored as 2 4-byte integers, so you can
convert the datetime to a binary(8), take the first 4 bytes and concat
0x00000000 to that and convert back to datetime to get zero hours, mins,
secs, & ms; but this method would not necessarily work on anything but SQL 2
k
32-bit.
As for a clustered index, only testing will tell...
KH
"Warren" wrote:
> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||If you're really interested in speed, don;t use DateTime column use an
integer or smallint.. and store the integer you get from Cast (getDate()
as Integer) directly. This reduces the size of the data in the column frm
8bytes to 4 bytes (oor 2 bytes if you use smallint) By reducing the width o
f
the index, you will dramatically increase the number of entries you will be
able to store on each IO Page of the index, and increase the performance
using the index.
NOTE: If you use smallints, then you need to subtract 32768 from the valu
you get from Cast(getdate() as Integer) before stuffing it into the smallint
field, because smallint is SIGNED 2-byte integer, but smalldatetime uses
UNSIGNED 2-byte integer..
SmallDatetime goes from Integer value 0 represesnting 1 jan 1900, to 65536
representing 6 June 2079... whereas smallint goes from -32768 to +32767...
Using Regular datetime is no problem, because it uses SIGNED 4-byte Integer,
with values from
January 1, 1753 through December 31, (this way value 0 still represents 1
Jan 1900... )
If your queries against this table often use date as a range of dates...
then a clustered index on this column will increase performance
draamatically.
"Warren" wrote:
> Hi,
> I currently have a column in a table that is a default of getdate()). My
> question : Is there a way to capture just the date without the time append
ed?
> For example, 04/04/2005. Question 2: How does SQL Server 2000 use indexe
s
> on this datetimestamp field? Would a clustered index on this field help?
> Almost all searching is done by the date field, whether it is searched by
day
> or a date range...Any better way than what is currently being done to help
> with speed ? Currently we have a clustered index on this column. The colu
mn
> currently contains approximately 12 million rows...
> Thanks for your input,
> Warren|||Thanks for all the replys...
I found out that the client application inserts the date stamp in the row of
the database. The colun is a dattime field, so it's not the getdate()) that
I thought it was..
Any more thoughts?
Thanks,
Warren
"CBretana" wrote:
> If you're really interested in speed, don;t use DateTime column use an
> integer or smallint.. and store the integer you get from Cast (getDate(
)
> as Integer) directly. This reduces the size of the data in the column fr
m
> 8bytes to 4 bytes (oor 2 bytes if you use smallint) By reducing the width
of
> the index, you will dramatically increase the number of entries you will b
e
> able to store on each IO Page of the index, and increase the performance
> using the index.
> NOTE: If you use smallints, then you need to subtract 32768 from the valu
> you get from Cast(getdate() as Integer) before stuffing it into the smalli
nt
> field, because smallint is SIGNED 2-byte integer, but smalldatetime uses
> UNSIGNED 2-byte integer..
> SmallDatetime goes from Integer value 0 represesnting 1 jan 1900, to 6553
6
> representing 6 June 2079... whereas smallint goes from -32768 to +32767...
> Using Regular datetime is no problem, because it uses SIGNED 4-byte Intege
r,
> with values from
> January 1, 1753 through December 31, (this way value 0 still represents 1
> Jan 1900... )
> If your queries against this table often use date as a range of dates...
> then a clustered index on this column will increase performance
> draamatically.
> "Warren" wrote:
>|||Then you need to
a) change the way the client write the data to strip off the time portion,
How is client writing to Database? using CLient constructed SQL,
Through a Stored Proc, etc.?
b) write an Insert/ update trigger on the database table that strips off the
time portion whenver client tries t owrite time into the table
In either case, To speed things up, same comments I made earlier about
datatypes still apply...
"Warren" wrote:
> Thanks for all the replys...
> I found out that the client application inserts the date stamp in the row
of
> the database. The colun is a dattime field, so it's not the getdate()) th
at
> I thought it was..
> Any more thoughts?
> Thanks,
> Warren
> "CBretana" wrote:
>sql
DateTime types and getdate() comparison
comparison syntax OK as is?
... where MyDate <= getdate()
Or is some formatting of the column value and/or of the function's
return value required for the comparison to work?
Thanks
LiamComparison operators (<,>,=, <>, >=, <= ) are allowed between two values wit
h
a datatype of datetime. Your expression is fine.
However, if you want to do things like add or subtract datetime values, you
will need to use the date and time functions in SQL Server.
"Liam" wrote:
> SQL 2000. Let's say column MyDate is a datetime type. Is this
> comparison syntax OK as is?
> .... where MyDate <= getdate()
> Or is some formatting of the column value and/or of the function's
> return value required for the comparison to work?
> Thanks
> Liam
>|||depends on what you need
but don't convert the column - you'll lose any sargability if it's indexed.
i tend not to try to rely on date data having being inserted with a time
of midnight, so i convert the variable and perform range queries
if you need mydate <= just the date: then do
MyDate < tomorrow at midnight
e.g.
where MyDate < dateadd(day, datediff(day, 0, getdate()), 0)+1
or if you need MyDate for just today
where MyDate >= dateadd(day, datediff(day, 0, getdate()), 0)
and MyDate < dateadd(day, datediff(day, 0, getdate()), 0)+1
or if you need mydate <= current date and time, then simply using
getdate() is appropriate.
Liam wrote:
> SQL 2000. Let's say column MyDate is a datetime type. Is this
> comparison syntax OK as is?
> ... where MyDate <= getdate()
> Or is some formatting of the column value and/or of the function's
> return value required for the comparison to work?
> Thanks
> Liam
Sunday, March 11, 2012
Datetime format
Getdate() fuction always returns value in 'yyyy-mm-dd hh:mi:ss.mmm' format
How do i customize this format?
For example i want the value like 'ddmonyyyy hh:mm'
Help required.
Thanx in anticipation.
'yyyy-mm-dd hh:mi:ss.mmm' is the way it is displayed in Query Analyzer. If
you want to have your datetime displayed differently, you have to use
CONVERT. CONVERT supports a number of formats, although it doesn't support
the one you want directly, but you can use REPLACE to remove spaces and LEFT
to remove any characters at the end you don't want.
Jacco Schalkwijk
SQL Server MVP
"Senthil" <anonymous@.discussions.microsoft.com> wrote in message
news:3CAFB558-6D38-4B09-BCA3-646F911D2C44@.microsoft.com...
> Hi all,
> Getdate() fuction always returns value in 'yyyy-mm-dd hh:mi:ss.mmm'
format
> How do i customize this format?
> For example i want the value like 'ddmonyyyy hh:mm'
> Help required.
> Thanx in anticipation.
|||You can also use function DATEPART() to retrieve parts of
date, and append them to get the format you require.
Shrikant Patil
MCDBA
>--Original Message--
> Hi all,
> Getdate() fuction always returns value in 'yyyy-mm-dd
hh:mi:ss.mmm' format
> How do i customize this format?
> For example i want the value like 'ddmonyyyy hh:mm'
> Help required.
> Thanx in anticipation.
>.
>
Datetime format
Getdate() fuction always returns value in 'yyyy-mm-dd hh:mi:ss.mmm' format
How do i customize this format?
For example i want the value like 'ddmonyyyy hh:mm'
Help required.
Thanx in anticipation.'yyyy-mm-dd hh:mi:ss.mmm' is the way it is displayed in Query Analyzer. If
you want to have your datetime displayed differently, you have to use
CONVERT. CONVERT supports a number of formats, although it doesn't support
the one you want directly, but you can use REPLACE to remove spaces and LEFT
to remove any characters at the end you don't want.
Jacco Schalkwijk
SQL Server MVP
"Senthil" <anonymous@.discussions.microsoft.com> wrote in message
news:3CAFB558-6D38-4B09-BCA3-646F911D2C44@.microsoft.com...
> Hi all,
> Getdate() fuction always returns value in 'yyyy-mm-dd hh:mi:ss.mmm'
format
> How do i customize this format?
> For example i want the value like 'ddmonyyyy hh:mm'
> Help required.
> Thanx in anticipation.|||You can also use function DATEPART() to retrieve parts of
date, and append them to get the format you require.
Shrikant Patil
MCDBA
>--Original Message--
> Hi all,
> Getdate() fuction always returns value in 'yyyy-mm-dd
hh:mi:ss.mmm' format
> How do i customize this format?
> For example i want the value like 'ddmonyyyy hh:mm'
> Help required.
> Thanx in anticipation.
>.
>
Datetime format
Getdate() fuction always returns value in 'yyyy-mm-dd hh:mi:ss.mmm' forma
How do i customize this format
For example i want the value like 'ddmonyyyy hh:mm
Help required
Thanx in anticipation.'yyyy-mm-dd hh:mi:ss.mmm' is the way it is displayed in Query Analyzer. If
you want to have your datetime displayed differently, you have to use
CONVERT. CONVERT supports a number of formats, although it doesn't support
the one you want directly, but you can use REPLACE to remove spaces and LEFT
to remove any characters at the end you don't want.
--
Jacco Schalkwijk
SQL Server MVP
"Senthil" <anonymous@.discussions.microsoft.com> wrote in message
news:3CAFB558-6D38-4B09-BCA3-646F911D2C44@.microsoft.com...
> Hi all,
> Getdate() fuction always returns value in 'yyyy-mm-dd hh:mi:ss.mmm'
format
> How do i customize this format?
> For example i want the value like 'ddmonyyyy hh:mm'
> Help required.
> Thanx in anticipation.|||You can also use function DATEPART() to retrieve parts of
date, and append them to get the format you require.
Shrikant Patil
MCDBA
>--Original Message--
> Hi all,
> Getdate() fuction always returns value in 'yyyy-mm-dd
hh:mi:ss.mmm' format
> How do i customize this format?
> For example i want the value like 'ddmonyyyy hh:mm'
> Help required.
> Thanx in anticipation.
>.
>
Thursday, March 8, 2012
DATETIME Default getDate() query
I have created a datagrid within an ASP.NET page that links to an SQL
table - this works just fine. One of the columns retrieves the date which a
particular row was populated. However, the format
which the date is returned is:
19.12.2004 13:03:25
I only want to display the date that the row was populated, not the exact
time as well. When I created the table I used the following code (I've cut
out the rest of the fields):
CREATE TABLE Users
(
Paul,
You can use this as your default:
Default dateadd(d,0,datediff(d,0,getdate()))
It works by finding the number of day boundaries between day 0 (January
1, 1900) and now, and adds that many days back to day 0.
Steve Kass
Drew University
Paul Evans wrote:
>Hi,
>I have created a datagrid within an ASP.NET page that links to an SQL
>table - this works just fine. One of the columns retrieves the date which a
>particular row was populated. However, the format
>which the date is returned is:
>19.12.2004 13:03:25
>I only want to display the date that the row was populated, not the exact
>time as well. When I created the table I used the following code (I've cut
>out the rest of the fields):
>CREATE TABLE Users
>(
> .
> .
> .
> .
> u_entrydate DATETIME Default getDate()
>)
>
>Is this to do with the DATETIME Default getDate() code for creating the
>column? Is there something else I could use to get just the date only, with
>out the time of day the row was populated?
>I'm using a microsoft SQL server.
>Thanks for your time
>Paul Evans
>P.S. or is it a problem with my ASP.NET code?
>
>
Datetime convert problem
result is 1/23/2006 but i want result in 01/23/2005
what am i doing wrong. Any db settings?I'd suggest you use the ISO standard date 112 instead, eg:-
select CAST(CONVERT(char, GETDATE(), 112) AS datetime)
Here's why :-
SET language english
SELECT ISDATE('31 Jan 2005')
SELECT ISDATE('20050131')
GO
SET language french
SELECT ISDATE('31 Jan 2005')
SELECT ISDATE('20050131')
GO
HTH. Ryan
"Mubashir Khan" <m@.n.com> wrote in message
news:%23vPXuIDIGHA.2212@.TK2MSFTNGP15.phx.gbl...
>i am using select CONVERT(varchar(15),getdate(),101)
> result is 1/23/2006 but i want result in 01/23/2005
> what am i doing wrong. Any db settings?
>|||But i need date in MM/dd/yyyy format.
cant use 112 which is yyyyMMdd
"Ryan" <Ryan_Waight@.nospam.hotmail.com> wrote in message
news:%23v29kODIGHA.1188@.TK2MSFTNGP14.phx.gbl...
> I'd suggest you use the ISO standard date 112 instead, eg:-
> select CAST(CONVERT(char, GETDATE(), 112) AS datetime)
> Here's why :-
> SET language english
> SELECT ISDATE('31 Jan 2005')
> SELECT ISDATE('20050131')
> GO
>
> SET language french
> SELECT ISDATE('31 Jan 2005')
> SELECT ISDATE('20050131')
> GO
>
> --
> HTH. Ryan
> "Mubashir Khan" <m@.n.com> wrote in message
> news:%23vPXuIDIGHA.2212@.TK2MSFTNGP15.phx.gbl...
>|||In that case this may be of use to you :-
http://www.aspfaq.com/show.asp?id=2460
HTH. Ryan
"Mubashir Khan" <m@.n.com> wrote in message
news:Ox8PvWDIGHA.3944@.tk2msftngp13.phx.gbl...
> But i need date in MM/dd/yyyy format.
> cant use 112 which is yyyyMMdd
> "Ryan" <Ryan_Waight@.nospam.hotmail.com> wrote in message
> news:%23v29kODIGHA.1188@.TK2MSFTNGP14.phx.gbl...
>|||"Mubashir Khan" <m@.n.com> wrote in message
news:%23vPXuIDIGHA.2212@.TK2MSFTNGP15.phx.gbl...
>i am using select CONVERT(varchar(15),getdate(),101)
> result is 1/23/2006 but i want result in 01/23/2005
> what am i doing wrong. Any db settings?
It works on sql server 2000. Perhaps this is a problem with the tool you
are using to view the results.|||no use
<snip>
WHEN 'MM/DD/YYYY' THEN
CONVERT(CHAR(10), @.dt, 101)
</snip>
"Ryan" <Ryan_Waight@.nospam.hotmail.com> wrote in message
news:Oh0EueDIGHA.216@.TK2MSFTNGP15.phx.gbl...
> In that case this may be of use to you :-
> http://www.aspfaq.com/show.asp?id=2460
> --
> HTH. Ryan
> "Mubashir Khan" <m@.n.com> wrote in message
> news:Ox8PvWDIGHA.3944@.tk2msftngp13.phx.gbl...
>|||it works fine on query analyzer
but it doesnot work when it is placed in a trigger.
trigger files it in some db table :'?
"Scott Morris" <bogus@.bogus.com> wrote in message
news:%23SfFqgDIGHA.1676@.TK2MSFTNGP09.phx.gbl...
> "Mubashir Khan" <m@.n.com> wrote in message
> news:%23vPXuIDIGHA.2212@.TK2MSFTNGP15.phx.gbl...
> It works on sql server 2000. Perhaps this is a problem with the tool you
> are using to view the results.
>|||> it works fine on query analyzer
> but it doesnot work when it is placed in a trigger.
> trigger files it in some db table :'?
That wasn't the question you asked. The responses you have received assume
that you are having problems with the output formats - that, indeed, is not
the problem at all. Perhaps you need to read the following:
http://www.aspfaq.com/show.asp?id=2023
Tibor has some information that explains this in a format that is more
user-friendly, but it appears to be down. Have a look at it (with respect
to datetime values) when it comes back up.
http://www.karaszi.com/sqlserver/articles.asp
If that does not clear up the problem, then define "doesn't work".
Wednesday, March 7, 2012
DATETIME as Primary Key
We have a strange issue.
Environment:
SQL 2K SP3a
TableA Definitioin:
Col1 varchar(10) NOT NULL
Col2 datetime NOT NULL default getdate()
Primary Key col1 and col2
Many inserts are occuring and we are receiving primary key vilolations.
The Insert statement does not explicitly select the datetime just uses the
default on the column declaration.
I.E INSERT TABLE1(col1)
SELECT 'TEST' FROM MyTable
Anyone have an idea why?Fred,
datetime measures time only in increments of 1/300 of a
second. Many rows can be inserted within a single "tick"
of datetime, and apparently this is the case for you, some
of them having matching Col1 values.
It sounds like (Col1, Col2) is not a good choice of primary key.
Steve Kass
Drew University
FredG wrote:
>Hello All,
>We have a strange issue.
>Environment:
>SQL 2K SP3a
>TableA Definitioin:
>Col1 varchar(10) NOT NULL
>Col2 datetime NOT NULL default getdate()
>Primary Key col1 and col2
>Many inserts are occuring and we are receiving primary key vilolations.
>The Insert statement does not explicitly select the datetime just uses the
>default on the column declaration.
>I.E INSERT TABLE1(col1)
> SELECT 'TEST' FROM MyTable
>Anyone have an idea why?
>
>|||Hi Steve,
That makes great sense. So, if the inserts are happening very frequently,
within that 1/300 of a second window, this would cause the error.
"Steve Kass" wrote:
> Fred,
> datetime measures time only in increments of 1/300 of a
> second. Many rows can be inserted within a single "tick"
> of datetime, and apparently this is the case for you, some
> of them having matching Col1 values.
> It sounds like (Col1, Col2) is not a good choice of primary key.
> Steve Kass
> Drew University
> FredG wrote:
>
>|||That's because rows (with the same Col1 value) are being inserted
within 300 milliseconds of each other
Denis the SQL Menace
http://sqlservercode.blogspot.com/
FredG wrote:
> Hello All,
> We have a strange issue.
> Environment:
> SQL 2K SP3a
> TableA Definitioin:
> Col1 varchar(10) NOT NULL
> Col2 datetime NOT NULL default getdate()
> Primary Key col1 and col2
> Many inserts are occuring and we are receiving primary key vilolations.
> The Insert statement does not explicitly select the datetime just uses the
> default on the column declaration.
> I.E INSERT TABLE1(col1)
> SELECT 'TEST' FROM MyTable
> Anyone have an idea why?|||FredG wrote:
> Hello All,
> We have a strange issue.
> Environment:
> SQL 2K SP3a
> TableA Definitioin:
> Col1 varchar(10) NOT NULL
> Col2 datetime NOT NULL default getdate()
> Primary Key col1 and col2
> Many inserts are occuring and we are receiving primary key vilolations.
> The Insert statement does not explicitly select the datetime just uses the
> default on the column declaration.
> I.E INSERT TABLE1(col1)
> SELECT 'TEST' FROM MyTable
> Anyone have an idea why?
If your inserts occur less than 1/300th of a second apart or if you do
multiple row inserts then you will get duplicates. Also you've used
local time, which means you could get duplicates if your local time is
adjusted for DST and then back again.
If you need to record time more precisely then you'll have to populate
some other time value without relying on GETDATE() and DATETIME.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Hi David,
You mention that duplicate values would be generated because of DST.
How would you get around this problem? I've never really thought about
it until seeing your post.
I don't have a specific example or problem - just curious really.
Thanks
Barry|||Barry wrote:
> Hi David,
> You mention that duplicate values would be generated because of DST.
> How would you get around this problem? I've never really thought about
> it until seeing your post.
Always make sure that your system is down for maintenance during that
one hour window each year :-)
-Tom.|||Ha! I like your style...just kick the plug out ;-)|||Barry wrote:
> Hi David,
> You mention that duplicate values would be generated because of DST.
> How would you get around this problem? I've never really thought about
> it until seeing your post.
> I don't have a specific example or problem - just curious really.
> Thanks
> Barry
Use GETUTCDATE() instead.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Ah right ok.
Thanks
Barry
Saturday, February 25, 2012
dates and Time Comparisons
if i use this to parse the current date to the right side of the time.
right(getdate(),7) - i'll get something like 7:30AM.
i also have Times stored in a column of a table, but as a string not a date time.
it seems to compare okay, but when the time is say 1:30PM and im comparing it if its greater than or equal to (>=)to 7:30AM - it doesnt return.
i think its ignoring the AM/PM Meridian Values and just comparing the numbers.
is there a conversion i could use to do this?
ive tried a military time conversion i found but it converts to hrs,min,milliseconds.
convert(char(8),(convert(datetime,current_timestam p,113)),114)
if anyone knows a good way to do this - i would appreciate it.
thanks again
rikI think i may have a solution to this, but, i probably should make this a UDF.
using military time and reading from the left rather than right :::
select left(convert(char(8),(convert(datetime,'7:33AM',11 3)),114),5)
gives me 07:33 -
which if i compare it to
select left(convert(char(8),(convert(datetime,'1:33PM',11 3)),114),5)
i'll get 13:33 and can compare too 07:33 just fine.
does that sound about right?
Friday, February 24, 2012
datepart("dw",Now())
Microsoft Sql Server Management Studio.
However, the function " datepart("dw", Now()) " doesn't work on report.
Is there someone who got the idea why it doesn't work?
Is there any other function which works same on report?
-KenYes. Reporting services uses the .Net langauge instead of TSQL. You can use
the following:
now.DayOfWeek
"MS newsgroup" wrote:
> the function "datepart(dw, getdate())" works just fine on
> Microsoft Sql Server Management Studio.
> However, the function " datepart("dw", Now()) " doesn't work on report.
> Is there someone who got the idea why it doesn't work?
> Is there any other function which works same on report?
>
> -Ken
>
>|||could you tell me more specifically?
do I need to use then "datepart("dw", now.DayOfWeek
)"
Main goal is return integer depending on the dayofweek.
Thanks
if sunday =1, saturday=7
"QM06" <QM06@.discussions.microsoft.com> wrote in message
news:7F34F2EC-1394-4827-96AE-1360260A75CC@.microsoft.com...
> Yes. Reporting services uses the .Net langauge instead of TSQL. You can
> use
> the following:
> now.DayOfWeek
> "MS newsgroup" wrote:
>> the function "datepart(dw, getdate())" works just fine on
>> Microsoft Sql Server Management Studio.
>> However, the function " datepart("dw", Now()) " doesn't work on report.
>> Is there someone who got the idea why it doesn't work?
>> Is there any other function which works same on report?
>>
>> -Ken
>>|||Datepart is not needed. Just use Now.dayofweek. You'll get your integer and
that's that.
"MS newsgroup" wrote:
> could you tell me more specifically?
> do I need to use then "datepart("dw", now.DayOfWeek
> )"
> Main goal is return integer depending on the dayofweek.
> Thanks
> if sunday =1, saturday=7
>
> "QM06" <QM06@.discussions.microsoft.com> wrote in message
> news:7F34F2EC-1394-4827-96AE-1360260A75CC@.microsoft.com...
> > Yes. Reporting services uses the .Net langauge instead of TSQL. You can
> > use
> > the following:
> > now.DayOfWeek
> >
> > "MS newsgroup" wrote:
> >
> >> the function "datepart(dw, getdate())" works just fine on
> >> Microsoft Sql Server Management Studio.
> >> However, the function " datepart("dw", Now()) " doesn't work on report.
> >>
> >> Is there someone who got the idea why it doesn't work?
> >> Is there any other function which works same on report?
> >>
> >>
> >> -Ken
> >>
> >>
> >>
>
>|||It doesn't work if I use Now.dayofweek itself.
"QM06" <QM06@.discussions.microsoft.com> wrote in message
news:78DAE85A-14CC-4CC5-8266-07061B26F99A@.microsoft.com...
> Datepart is not needed. Just use Now.dayofweek. You'll get your integer
> and
> that's that.
> "MS newsgroup" wrote:
>> could you tell me more specifically?
>> do I need to use then "datepart("dw", now.DayOfWeek
>> )"
>> Main goal is return integer depending on the dayofweek.
>> Thanks
>> if sunday =1, saturday=7
>>
>> "QM06" <QM06@.discussions.microsoft.com> wrote in message
>> news:7F34F2EC-1394-4827-96AE-1360260A75CC@.microsoft.com...
>> > Yes. Reporting services uses the .Net langauge instead of TSQL. You can
>> > use
>> > the following:
>> > now.DayOfWeek
>> >
>> > "MS newsgroup" wrote:
>> >
>> >> the function "datepart(dw, getdate())" works just fine on
>> >> Microsoft Sql Server Management Studio.
>> >> However, the function " datepart("dw", Now()) " doesn't work on
>> >> report.
>> >>
>> >> Is there someone who got the idea why it doesn't work?
>> >> Is there any other function which works same on report?
>> >>
>> >>
>> >> -Ken
>> >>
>> >>
>> >>
>>|||If you're using this in the report body you could try this =now.dayofweek().
"MS newsgroup" wrote:
> It doesn't work if I use Now.dayofweek itself.
>
> "QM06" <QM06@.discussions.microsoft.com> wrote in message
> news:78DAE85A-14CC-4CC5-8266-07061B26F99A@.microsoft.com...
> > Datepart is not needed. Just use Now.dayofweek. You'll get your integer
> > and
> > that's that.
> >
> > "MS newsgroup" wrote:
> >
> >> could you tell me more specifically?
> >> do I need to use then "datepart("dw", now.DayOfWeek
> >> )"
> >>
> >> Main goal is return integer depending on the dayofweek.
> >>
> >> Thanks
> >> if sunday =1, saturday=7
> >>
> >>
> >> "QM06" <QM06@.discussions.microsoft.com> wrote in message
> >> news:7F34F2EC-1394-4827-96AE-1360260A75CC@.microsoft.com...
> >> > Yes. Reporting services uses the .Net langauge instead of TSQL. You can
> >> > use
> >> > the following:
> >> > now.DayOfWeek
> >> >
> >> > "MS newsgroup" wrote:
> >> >
> >> >> the function "datepart(dw, getdate())" works just fine on
> >> >> Microsoft Sql Server Management Studio.
> >> >> However, the function " datepart("dw", Now()) " doesn't work on
> >> >> report.
> >> >>
> >> >> Is there someone who got the idea why it doesn't work?
> >> >> Is there any other function which works same on report?
> >> >>
> >> >>
> >> >> -Ken
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
Sunday, February 19, 2012
DateName always return DatePart!
I have a Japanese SQL2K server that uses the following servertime format
returned by getdate() - 2005-11-23 23:29.
The problem i'm experiencing is when I use the DATENAME function, it returns
me the INT value for November (11) and not the name. Very weird. It works
correctly on my English server and i've never had this problem before using
DATENAME.
The selects are below:
SELECT DATEPART(month, GETDATE()) -- returns 11 - Correct
SELECT DATENAME(month,GETDATE()) -- returns 11 - Incorrect
Any help would be appreciated.
Regards
ImmyHi, Immy
The values returned by the DATENAME function can be in found the
syslanguages table (in the master database). Besides Japanese, this
problem also affects Korean and Chinese languages.
Razvan|||I know where I can find them , but that doesn't help the problem I am
having.
Simply, the DATENAME function should return the Name of the Day, Month
etc... but I always get the datepart int returned.
The syslanguages table on the "good" and "bad" server are exactly the same,
yet 1 server behaves correctly and the other as above!?
very
Immy
"Razvan Socol" <rsocol@.gmail.com> wrote in message
news:1132756544.307907.136100@.g47g2000cwa.googlegroups.com...
> Hi, Immy
> The values returned by the DATENAME function can be in found the
> syslanguages table (in the master database). Besides Japanese, this
> problem also affects Korean and Chinese languages.
> Razvan
>|||What do you want SQL Server to return ? "November" or the name of the
eleventh month in Japanese ?
If you want it to return "November", you can use one of the following
methods:
1. issue a "SET LANGUAGE ENGLISH" before executing your query
2. change the connection string to include "Current Language=English"
3. change the default language of the server, using one of the
following methods:
a) execute "EXEC sp_configure 'default language', 'English'
RECONFIGURE"
b) using Enterprise Manager, right click on your server, Properties /
Server Settings / Default language for user.
Razvan|||> 3. change the default language of the server, using one of the
> following methods:
> a) execute "EXEC sp_configure 'default language', 'English'
> RECONFIGURE"
> b) using Enterprise Manager, right click on your server, Properties /
> Server Settings / Default language for user.
Note that this setting will only affect the default language for new logins,
not for existing
logins.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Razvan Socol" <rsocol@.gmail.com> wrote in message
news:1132758818.247140.278630@.g49g2000cwa.googlegroups.com...
> What do you want SQL Server to return ? "November" or the name of the
> eleventh month in Japanese ?
> If you want it to return "November", you can use one of the following
> methods:
> 1. issue a "SET LANGUAGE ENGLISH" before executing your query
> 2. change the connection string to include "Current Language=English"
> 3. change the default language of the server, using one of the
> following methods:
> a) execute "EXEC sp_configure 'default language', 'English'
> RECONFIGURE"
> b) using Enterprise Manager, right click on your server, Properties /
> Server Settings / Default language for user.
> Razvan
>|||"Immy" <imtiaz_ullah@.hotmail.com> wrote in message
news:u7HgJwD8FHA.3760@.TK2MSFTNGP14.phx.gbl...
>I know where I can find them , but that doesn't help the problem I am
>having.
> Simply, the DATENAME function should return the Name of the Day, Month
> etc... but I always get the datepart int returned.
> The syslanguages table on the "good" and "bad" server are exactly the
> same, yet 1 server behaves correctly and the other as above!?
> very
> Immy
>
Hi Immy,
May I make a suggestion.
Our websites support both French and English but we have never used SQL
server to return the name of the month or w
SQL returns the 1-12 for months and 1-7 for days and we client side
functions to display the names in the language of choice.
When you say:
"It works correctly on my English server and i've never had this problem
before using DATENAME."
Do you mean it returns the correct English name or Japanese?
If you mean English and that server does not return the correct Japanese
name, then I suggest that you look at the sysLanguage table as Razvan has
suggested. You'll see that for Japanese, the language names are listed as
1,2,3,4,5... instead of the actual names.
I don't know the reason why.|||Tibor Karaszi wrote:
> Note that this setting will only affect the default language for new login
s,
> not for existing logins.
You are correct. I should have mentioned another method:
4. change the default language of the login used by your application,
using one of the following methods:
a) execute: EXEC sp_defaultlanguage 'YourLoginName', 'English'
b) using Enterprise Manager, go to "Security" / "Logins", double click
on your login, and change the "Language" setting under "General" /
"Defaults".
Razvan
DATENAME - can you not get it to say the actual day name?
SELECT DATENAME(day, getdate()) AS 'Day Name'
comes back as 15 but i want it to come back with thursday
Cheers,
Craig
use dw
SELECT DATENAME(dw, getdate()) AS 'Day Name'
this stuff is clearly documented in BOL with in the section on datename
|||what makes it worse is that i was sitting looking at datename page in BOL
jsut one of those days where you cant see the wood for the trees!!
soz,
Craig
Datediff -Year and Rounding
SELECT
DATEDIFF(year, acc.acct_anuit_birth_dt, GETDATE()) AS 'age'
FROM rpsacct_t acc
The acc.acct_anuit_birth_dt field is a date field. The statement returns
whole numbers based like 64 etc... What I would like it to do is to return
the age to two decimal places eg... if someone is 64 years and 6 months, I'd
like to get back 64.50 Any idea how I might do this ?
ThanksTry this:
SELECT
DATEDIFF(month, acc.acct_anuit_birth_dt, GETDATE())/12. AS age
FROM rpsacct_t acc
If this is not what you want, post more sample data and expected
results.
Razvan
datediff with parameter
I am trying to run the following query but want to use a parameter instaed
of the -7
BETWEEN GETDATE() AND DATEADD(d, -7, GETDATE())
ive tried BETWEEN GETDATE() AND DATEADD(d, @.date, GETDATE()) with the
parameter set is an int & text but to no avaial.
Thanks in advanceTry BETWEEN GETDATE() AND DATEADD("d",CONVERT(INT,@.date),GETDATE())
I got it to work by converting the param to INT. It appears SSRS
defaults params to the nvarchar datatype.
Hang in there
toolman
Tango wrote:
> Hi
> I am trying to run the following query but want to use a parameter instaed
> of the -7
> BETWEEN GETDATE() AND DATEADD(d, -7, GETDATE())
> ive tried BETWEEN GETDATE() AND DATEADD(d, @.date, GETDATE()) with the
> parameter set is an int & text but to no avaial.
> Thanks in advance
datediff question
Hello All!
I want to select records that are 24 hours old or older.
Here is my code
SELECT *, DATEDIFF(Hour, Service_Date_Time, getdate())AS Hours
FROM Active_Orders
WHERE (Status_ID = 4)
Not sure how I write the 24 hours part?
Any thoughtS
Thanks!
Rudy
Use a filter expression in the "where" clause.
SELECT *, DATEDIFF(Hour, Service_Date_Time, getdate()) AS Hours
FROM Active_Orders
WHERE (Status_ID = 4) and Service_Date_Time <= DATEADD(Hour, 24, getdate())
AMB
|||This may work for you:
Code Snippet
SELECT
{ColumnList},
Service_Date_Time
FROM Active_Orders
WHERE ( Status_ID = 4
AND Service_Date_Time >= dateadd( day, -1, getdate() )
)
You want to avoid using a function on the Service_Date_Time field since doing so would eliminate any chance of using indexing on the column.
*NOTE: (Using [ SELECT * ] is not a good idea, and is not in the accepted 'best practices'.)
|||Hi Arnie,
Good point about not manipulating the column in the filter expression (Mea culpa - I changed my post after reading yours). The OP wants 24 hours old or older.
...
WHERE ( Status_ID = 4
AND Service_Date_Time <= dateadd( day, -1, getdate() )
)
go
AMB
|||Thanks Alejandro,
I'm glad you caught the mistake -I was thinking 'FOR' the last 24 hours. Your change [ <= ] will catch those MORE than 24 hours.
|||WOW!
Thanks guys! Great suggestions!
Rudy
datediff question
Hello All!
I want to select records that are 24 hours old or older.
Here is my code
SELECT *, DATEDIFF(Hour, Service_Date_Time, getdate())AS Hours
FROM Active_Orders
WHERE (Status_ID = 4)
Not sure how I write the 24 hours part?
Any thoughtS
Thanks!
Rudy
Use a filter expression in the "where" clause.
SELECT *, DATEDIFF(Hour, Service_Date_Time, getdate()) AS Hours
FROM Active_Orders
WHERE (Status_ID = 4) and Service_Date_Time <= DATEADD(Hour, 24, getdate())
AMB
|||This may work for you:
Code Snippet
SELECT
{ColumnList},
Service_Date_Time
FROM Active_Orders
WHERE ( Status_ID = 4
AND Service_Date_Time >= dateadd( day, -1, getdate() )
)
You want to avoid using a function on the Service_Date_Time field since doing so would eliminate any chance of using indexing on the column.
*NOTE: (Using [ SELECT * ] is not a good idea, and is not in the accepted 'best practices'.)
|||Hi Arnie,
Good point about not manipulating the column in the filter expression (Mea culpa - I changed my post after reading yours). The OP wants 24 hours old or older.
...
WHERE ( Status_ID = 4
AND Service_Date_Time <= dateadd( day, -1, getdate() )
)
go
AMB
|||Thanks Alejandro,
I'm glad you caught the mistake -I was thinking 'FOR' the last 24 hours. Your change [ <= ] will catch those MORE than 24 hours.
|||WOW!
Thanks guys! Great suggestions!
Rudy
Friday, February 17, 2012
datediff function
DATEDIFF(day, mydatecolumn, GETDATE()) as numberofdays
but i want to only calculate the days where mydatecolumn isn't null - is
this possible ?
Select DATEDIFF(day, mydatecolumn, GETDATE()) as numberofdays
>From SomeTable
where mydatecolumn IS NOT NULL
Or what do you want to to withthese rows not containing a date ?
Inserting 0 ?
Select ISNULL(DATEDIFF(day, mydatecolumn, GETDATE()),0) as numberofdays
>From SomeTable
where mydatecolumn IS NOT NULL
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
|||Sorry, corrected second one.
Inserting 0 ?
Select ISNULL(DATEDIFF(day, mydatecolumn, GETDATE()),0) as numberofdays
>From SomeTable
|||"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1126605935.965506.214820@.g47g2000cwa.googlegr oups.com...
> Sorry, corrected second one.
> Inserting 0 ?
>
> Select ISNULL(DATEDIFF(day, mydatecolumn, GETDATE()),0) as numberofdays
>
thanks for the replies, did the job great, now how can i do this ?
(
select isnull(datediff(day,mydatecolumn1,mydatecolumn2),0 ) as numberofdays
if mydatecolumn2 is null then select
isnull(datediff(day,mydatecolumn1,GETDATE()),0) as numberofdays2 )
sorry to be a PITA
mark
|||As a batch that should be (two resultssets)
select isnull(datediff(day,mydatecolumn1,mydatecolumn2),0 ) as
numberofdays
if mydatecolumn2 is null
select isnull(datediff(day,mydatecolumn1,GETDATE()),0) as
numberofdays2
or in one statement
select isnull(datediff(day,mydatecolumn1,mydatecolumn2),0 ) as
numberofdays,
ISNULL(mydatecolumn2,isnull(datediff(day,mydatecol umn1,GETDATE()),0),0)
as numberofdays2
Did I understand your requirement right?
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
|||"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1126609542.543399.165310@.g44g2000cwa.googlegr oups.com...
> As a batch that should be (two resultssets)
> select isnull(datediff(day,mydatecolumn1,mydatecolumn2),0 ) as
> numberofdays
> if mydatecolumn2 is null
> select isnull(datediff(day,mydatecolumn1,GETDATE()),0) as
> numberofdays2
> or in one statement
> select isnull(datediff(day,mydatecolumn1,mydatecolumn2),0 ) as
> numberofdays,
> ISNULL(mydatecolumn2,isnull(datediff(day,mydatecol umn1,GETDATE()),0),0)
> as numberofdays2
> Did I understand your requirement right?
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
something like that
my query looks like this
select column1,column2,
datediff (day,column3,column4) as newcolumn1
then i need to do this :-
if column4 is null then select datediff(day,column3,getdate())
its almost there!, im cheating by pasting into excel !
thanks
mark
|||select column1,column2,
datediff (day,column3, ISNULL(column4, GetDate())) as newcolumn1
Nik Marshall-Blank MCSD/MCDBA
"mark" <mark@.remove.com> wrote in message
news:1126612753.14638.0@.ersa.uk.clara.net...
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1126609542.543399.165310@.g44g2000cwa.googlegr oups.com...
> something like that
> my query looks like this
> select column1,column2,
> datediff (day,column3,column4) as newcolumn1
> then i need to do this :-
> if column4 is null then select datediff(day,column3,getdate())
> its almost there!, im cheating by pasting into excel !
> thanks
> mark
>
>
>
datediff function
DATEDIFF(day, mydatecolumn, GETDATE()) as numberofdays
but i want to only calculate the days where mydatecolumn isn't null - is
this possible ?Select DATEDIFF(day, mydatecolumn, GETDATE()) as numberofdays
>From SomeTable
where mydatecolumn IS NOT NULL
Or what do you want to to withthese rows not containing a date ?
Inserting 0 ?
Select ISNULL(DATEDIFF(day, mydatecolumn, GETDATE()),0) as numberofdays
>From SomeTable
where mydatecolumn IS NOT NULL
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--|||Sorry, corrected second one.
Inserting 0 ?
Select ISNULL(DATEDIFF(day, mydatecolumn, GETDATE()),0) as numberofdays
>From SomeTable|||"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1126605935.965506.214820@.g47g2000cwa.googlegroups.com...
> Sorry, corrected second one.
> Inserting 0 ?
>
> Select ISNULL(DATEDIFF(day, mydatecolumn, GETDATE()),0) as numberofdays
>
>
thanks for the replies, did the job great, now how can i do this ?
(
select isnull(datediff(day,mydatecolumn1,mydate
column2),0) as numberofdays
if mydatecolumn2 is null then select
isnull(datediff(day,mydatecolumn1,GETDAT
E()),0) as numberofdays2 )
sorry to be a PITA
mark|||As a batch that should be (two resultssets)
select isnull(datediff(day,mydatecolumn1,mydate
column2),0) as
numberofdays
if mydatecolumn2 is null
select isnull(datediff(day,mydatecolumn1,GETDAT
E()),0) as
numberofdays2
or in one statement
select isnull(datediff(day,mydatecolumn1,mydate
column2),0) as
numberofdays,
ISNULL(mydatecolumn2,isnull(datediff(day
,mydatecolumn1,GETDATE()),0),0)
as numberofdays2
Did I understand your requirement right?
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--|||"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1126609542.543399.165310@.g44g2000cwa.googlegroups.com...
> As a batch that should be (two resultssets)
> select isnull(datediff(day,mydatecolumn1,mydate
column2),0) as
> numberofdays
> if mydatecolumn2 is null
> select isnull(datediff(day,mydatecolumn1,GETDAT
E()),0) as
> numberofdays2
> or in one statement
> select isnull(datediff(day,mydatecolumn1,mydate
column2),0) as
> numberofdays,
> ISNULL(mydatecolumn2,isnull(datediff(day
,mydatecolumn1,GETDATE()),0),0)
> as numberofdays2
> Did I understand your requirement right?
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
something like that
my query looks like this
select column1,column2,
datediff (day,column3,column4) as newcolumn1
then i need to do this :-
if column4 is null then select datediff(day,column3,getdate())
its almost there!, im cheating by pasting into excel !
thanks
mark|||select column1,column2,
datediff (day,column3, ISNULL(column4, GetDate())) as newcolumn1
Nik Marshall-Blank MCSD/MCDBA
"mark" <mark@.remove.com> wrote in message
news:1126612753.14638.0@.ersa.uk.clara.net...
> "Jens" <Jens@.sqlserver2005.de> wrote in message
> news:1126609542.543399.165310@.g44g2000cwa.googlegroups.com...
> something like that
> my query looks like this
> select column1,column2,
> datediff (day,column3,column4) as newcolumn1
> then i need to do this :-
> if column4 is null then select datediff(day,column3,getdate())
> its almost there!, im cheating by pasting into excel !
> thanks
> mark
>
>
>
DateDiff / DateAdd - please help me:(
hello,
i have a Pictures table: PictureID, Name, Description, DateAdded (GETDATE() when insert), IsActive...
i need to make some stored procedures to show me the pictures added in last 24hours, in last 3 days, last 2 weeks and so on
the pictures added in database are active (available to be seen by users) only 1yaer after the date added
I tryied to make a stored procedure (in fact i maked a lots of them, for 1day 3 days 1 week 1 month), but i have a problem with that DateDiff and DateAdd
Here is what i tryied
CREATE PROCEDURE LastAdded_2monthsAgoASSELECT Pictures.ProductID, Pictures.Name, Pictures.Description, Pictures.DateAddedFROM PicturesWHERE (DATEDIFF(month, Pictures.DateAdded,GETDATE()) >= 0)AND (DATEDIFF(month, Pictures.DateAdded,GETDATE()) <= 2)ORDER BY DateAddedDesc
I have a feeling that is wrong, please make your own version and show me what i should write...I don't know what should be first the today date or the DateAdded...
i need to select the last added products from a specific interval of time...
Should i do something with that "1 year available" likeWHERE (DATEDIFF(month,GETDATE(),DATEADD(year, 1, Products.DateAdded)) >= 0)AND (DATEDIFF(month,GETDATE(),DATEADD(year, 1, Products.DateAdded)) <= 2)I am sure is a stupid thig up there...if you can, make your own version how you would do it and show me..please help me
The simplest way to do this would be with a single stored procedure, and pass in the two dates to search between. (make sure you use a standard time scheme in order for this to be accurate, such as UTC/GMT.)
I suggest creating the start and end date in your [web] application, and your procedure should be like that below:
CREATE PROCEDURE LastAdded_2monthsAgo @.StartDatedatetime, @.EndDatedatetimeASSELECT Pictures.ProductID, Pictures.[Name], Pictures.[Description], Pictures.DateAddedFROM PicturesWHERE (Pictures.DateAddedBETWEEN @.StartDateAND @.EndDate)ORDER BY DateAddedDesc
Also note that you are using keywords for column names, which is why they show up blue. While this will still work in some cases, it is best to qualify the keyword as a column, which is why I used square brackets around those 2 column names. (Some people do this with every column.)
|||LAST 24 HOURS:
WHERE Pictures.DateAdded >= DATEADD(DD,-1,GETDATE())
LAST 3 DAYS:
WHERE Pictures.DateAdded >= DATEADD(DD,-3,GETDATE())
LAST 2 WEEKS:
WHERE Pictures.DateAdded >= DATEADD(DD,-14,GETDATE())
SAMPLE SPROC:
CREATE PROCEDURE LastAdded_2monthsAgo
@.Number_Of_Days int
AS
SELECT Pictures.ProductID, Pictures.Name, Pictures.Description, Pictures.DateAdded
FROM Pictures
WHERE Pictures.DateAdded >= DATEADD(DD,@.Number_Of_Days, GetDate())
ORDER BY DateAddedDesc
Hope this helps,
I should also clarify that when you are building your dates to search between, the first should have a time of 12:00 (midnight), and the end date should end at 11:59 PM. So if you are searching just for today's uploaded files, you would search between "9/28/2007 12:00:00 AM" and "9/28/2007 11:59:59 PM".
|||It's usually better if you use midnight the next day as the end point (It avoids date/time accuracy issues).
Like;
WHERE MyDATE>='9/28/2007 12:00:00 AM' AND MyDate<'9/29/2007 12:00:00 AM'
or more concisely:
WHERE MyDate>='9/28/2007' AND MyDate<'9/29/2007'
|||thank you to all for helping me
to show the pictures from the last 2 days or more i user the rhp_72 stored procedure,
and to show the pictures from a specific interval of time i used the ps2goat stored procedure
thank you, you resolved my problem
Tuesday, February 14, 2012
DateAdd() in Default Value
My goal is to set the default value of a smalldatetime field to the GetDate() plus 4 hours. I figure I need to use DateAdd() for this, but can't figure out how to place it in a default value. I can put GetDate() in default value, but DateAdd(hour,4,GetDate()) throws a syntax error.
Is there a simple way to accomplish this?
bes7252,What error are you seeing, exactly? I have no problem executing the following code:
create table t(
i int,
d datetime default (dateadd(hour,3,getdate()))
)
go
drop table t
Have you left out a ) somewhere?
Steve Kass
Drew University
http://www.stevekass.com
|||
Logically it doesn’t make any sense to have this expression on your column. Suppose if you generate the expression on your stored date then it is acceptable.
|||Steve,
I tried it again and didn't have any problems. I don't remember the error I was seeing yesterday, but must have had a typo-o in my expression. (I typed the one on the post from memory, not copy/paste).
Thanks!
Brian