Showing posts with label store. Show all posts
Showing posts with label store. Show all posts

Thursday, March 22, 2012

DateTime with TimeZone ?

Are there any plans to enhance the DateTime datatype to be able to store a timezone, and provide timezone aware arithmetic functions ?

The lack of timezone support seems a glaring omission - especially given that Microsoft's biggest DB competitor (Oracle) has a timestamp with timezone datatype. At present, you have to code all this yourself in SQL 2005. Is this not something that should be built into the DBMS ?

Thanks,

Andy Mackie

You can store it as UTC.

HTH, Jens Suessmeyer.

datetime type for debugging store procedure

Some of the pass-in parameters in my store procedure are datetime
type. I have tried to enter parameters in the debug window in the
QueryAnalyzer, but everytime it came back with error
[Microsoft][ODBC SQL Server Driver]Invalid character value for cast
specification
The parameters I have tried are:
1/1/1998
'1/1/1998'
#1/1/1998#
What should I enter in the debug window for the datetime?
Thanks,
AlanTry '19980101'
Andrew J. Kelly
SQL Server MVP
"Alan" <alan_test@.yahoo.com> wrote in message
news:rdhjgvs83vclf99359l9c1sjm6d3q76c2k@.4ax.com...
> Some of the pass-in parameters in my store procedure are datetime
> type. I have tried to enter parameters in the debug window in the
> QueryAnalyzer, but everytime it came back with error
> [Microsoft][ODBC SQL Server Driver]Invalid character value for cast
> specification
> The parameters I have tried are:
> 1/1/1998
> '1/1/1998'
> #1/1/1998#
> What should I enter in the debug window for the datetime?
> Thanks,
> Alan|||Thanks for reply, but I just tried both
'19980101'
19980101
It came back with same error message.
Alan
On Mon, 7 Jul 2003 15:24:41 -0400, "Andrew J. Kelly"
<sqlmvpnooospam@.shadhawk.com> wrote:
>Try '19980101'|||Sorry. I remember now that you must use the format as follows (Taken from
BOL):
{ ts 'yyyy-mm-dd hh:mm:ss[.fff] '} such as: { ts '1998-09-24 10:02:20' }
{ d 'yyyy-mm-dd'} such as: { d '1998-09-24' }
{ t 'hh:mm:ss'} such as: { t '10:02:20'}
This is the international way to format dates and times in ODBC and OLEDB.
--
Andrew J. Kelly
SQL Server MVP
"Alan" <alan_test@.yahoo.com> wrote in message
news:qrjjgvoiu0oj3bjon5fk7mt8l565ujevpj@.4ax.com...
> Thanks for reply, but I just tried both
> '19980101'
> 19980101
> It came back with same error message.
>
> Alan
> On Mon, 7 Jul 2003 15:24:41 -0400, "Andrew J. Kelly"
> <sqlmvpnooospam@.shadhawk.com> wrote:
> >Try '19980101'
>|||1998-09-24 10:02:20 works.
Thanks a lot.
Alan
On Mon, 7 Jul 2003 17:18:38 -0400, "Andrew J. Kelly"
<sqlmvpnooospam@.shadhawk.com> wrote:
>Sorry. I remember now that you must use the format as follows (Taken from
>BOL):
>{ ts 'yyyy-mm-dd hh:mm:ss[.fff] '} such as: { ts '1998-09-24 10:02:20' }
>{ d 'yyyy-mm-dd'} such as: { d '1998-09-24' }
>{ t 'hh:mm:ss'} such as: { t '10:02:20'}
>
>This is the international way to format dates and times in ODBC and OLEDB.sql

Monday, March 19, 2012

DateTime Issue

I don't like store time in smalldatetime field owing to application limitation, Is there any solution, let me help matter is most urgent and my application is too big.
Thanking You
R.MallWhat is the application limitation?? do u need to run queries aganist this column??|||What is the application limitation?? do u need to run queries aganist this column??

In totality it is big application already developped in PowerBuilder 7.3 and fullfill the need of business. That was with sybase, rightnow I am looking to port this data into MSSQL Server and application also tested on the MSSQL Server 2000, It is working as per need apart from date issue. Sybase doesn't need to store time with date, So I am looking similar datatype which doesn't need to store timestamp in date columns.

Is the any way to resolve this issue at database level.

Thanks

R.Mall|||Hi,

SQL Server do not support Time data type as such...So to store a time only data u will have to store the integer portion of datetime datatype as 0 ...(i.e January 1, 1900)...

But then if ur application does not allow u to use datetime datatype...may be try with CHAR......|||How I can store only integer part in datetime colmns.

Thanks|||How I can store only integer part in datetime colmns.make sure when you save a datetime value that you do not provide a time value as well

so INSERT ... VALUES ... ( '2004-10-27' ... ) is okay, and the time portion of the value is set to 00:00:00

however, INSERT ... VALUES ... ( getdate() ... ) includes a time

if you want to strip the time, use

... cast(convert(char(10),getdate(),120) as datetime)

datetime Issue

i have a datetime field that i'm just storing the date like 5/17/2005.
i need to add the time like 10:30 PM to it. Should I store the time in
another field and concatenate? Right now, i just have a calendar date picker
on user form and will add time drop down fields to handle time.
any suggestions?I would recommend storing both the Date and Time in the one column since
combined they represent a single instance in time. Let the GUI, business or
data
layers combine the data into a single DateTime value.
Thomas
"scott" <sbailey@.mileslumber.com> wrote in message
news:e4%23rIu$WFHA.2448@.TK2MSFTNGP12.phx.gbl...
>i have a datetime field that i'm just storing the date like 5/17/2005.
> i need to add the time like 10:30 PM to it. Should I store the time in ano
ther
> field and concatenate? Right now, i just have a calendar date picker on us
er
> form and will add time drop down fields to handle time.
> any suggestions?
>|||>> i have a datetime field [sic] that i'm just storing the date like
5/17/2005.<<
No, you are not. If it were a field, then you can put anything into
it, but a column (which is nothing like a field) has a data type, and
the DATETIME data type includes year, month, day, hour, minute, second
and fractional second.
Also, that string you showed has nothing whatsoevdr to do with the
storage of temporal data. That is display and display is a task for
the front end, not the database. You might also want to start using
ISO-8601 temporal formats instead of "local dialect" -- this Internet
thing might catch on, you might need to exchange data, avoid errors,
etc.|||> You might also want to start using
> ISO-8601 temporal formats instead of "local dialect"
That is interesting! Joe suggests using non-ANSI SQL compliant elements. IS
O 8601 is
'2004-05-23T14:12:23', and this format is not supported in ANSI SQL. In ANSI
SQL, you need to
replace the T with a blank, but that makes it language and datetime dependen
t in SQL Server.
Scott, for datetime format recommendations, I suggest you check out:
http://www.karaszi.com/SQLServer/info_datetime.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1116457963.195486.21040@.g44g2000cwa.googlegroups.com...
> 5/17/2005.<<
> No, you are not. If it were a field, then you can put anything into
> it, but a column (which is nothing like a field) has a data type, and
> the DATETIME data type includes year, month, day, hour, minute, second
> and fractional second.
> Also, that string you showed has nothing whatsoevdr to do with the
> storage of temporal data. That is display and display is a task for
> the front end, not the database. You might also want to start using
> ISO-8601 temporal formats instead of "local dialect" -- this Internet
> thing might catch on, you might need to exchange data, avoid errors,
> etc.
>

Sunday, March 11, 2012

DateTime format problem

Hi,
I have a datetime field that store data in format like this following format:
2003-05-25 13:01:39.400
How can I change the format of the of the datetime to 13:01:39.400 only.
ThanksSELECT CONVERT(VARCHAR,GETDATE(),114)

This query will show you what all the datetime conversions look like. You can see why they look like they do by lookup up CONVERT in Books Online.

SET NOCOUNT ON

DECLARE
@.min INT,
@.max INT,
@.date DATETIME

SELECT
@.min = 1,
@.max = 131,
@.date = GETDATE()

SELECT @.date

WHILE @.min <= @.max
BEGIN

IF @.min BETWEEN 15 AND 19
OR @.min = 26
OR @.min BETWEEN 27 AND 99
OR @.min BETWEEN 115 AND 119
OR @.min BETWEEN 122 AND 125
OR @.min BETWEEN 127 AND 129
BEGIN
GOTO NEXT_LOOP
END

SELECT @.min, CONVERT(VARCHAR,@.date,@.min)

NEXT_LOOP:

SELECT @.min = @.min + 1
END

Datetime field

Hello,

I need to show only the date and not the date and time in a datetime field. How do I do this ? EG only store date not date and time.

I want to do this via enterprise manager

Many thanks

GrantEnterprise manager will show you the whole thing by default. making a view with an appropriate CAST operation in it might help you - does this sound like the kind of thing you're after?|||print convert(varchar(10), getdate(), 103)

Look up CONVERT in BOL for other formats. Cast sucks on dates.

Thursday, March 8, 2012

DateTime Data Type

Hi,
I am new to SQL Server, I am using SQL Server 2000, I want to store only
date (not time) in my table, is it possible in sql , is there any data types
except datetime and smalldatetime.
Thanks in advance.
Hardik Shah.Hardik Shah wrote:
> Hi,
> I am new to SQL Server, I am using SQL Server 2000, I want to store
> only date (not time) in my table, is it possible in sql , is there
> any data types except datetime and smalldatetime.
>
> Thanks in advance.
>
> Hardik Shah.
No, you need to store a time portion as well. You can set it to 12am if
you want. Use a smalldatatime if you don't require full time precision
as it's only 4 bytes instead of 8.
David Gugick
Imceda Software
www.imceda.com|||No. Sql2k does not have date only datatype.
Here is Tibor's excellent article on the subject. I would suggest you take a
quick look.
http://www.karaszi.com/sqlserver/info_datetime.asp
-oj
"Hardik Shah" <har_sha_99@.hotmail.com> wrote in message
news:OvHsm9NTFHA.2560@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am new to SQL Server, I am using SQL Server 2000, I want to store only
> date (not time) in my table, is it possible in sql , is there any data
> types
> except datetime and smalldatetime.
>
> Thanks in advance.
>
> Hardik Shah.
>|||No and no to both questions.
When you write a date to the column, you can save it as so:
'20050429'
The time part will be '00:00:00.000'
So a query: ...where dateColumn = '20050429'
will return that row.
You must be coming from Access, right?
"Hardik Shah" <har_sha_99@.hotmail.com> wrote in message
news:OvHsm9NTFHA.2560@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am new to SQL Server, I am using SQL Server 2000, I want to store only
> date (not time) in my table, is it possible in sql , is there any data
> types
> except datetime and smalldatetime.
>
> Thanks in advance.
>
> Hardik Shah.
>|||By default, no. However, there are numerous tricks to accomplish the same go
al.
1. Use a smallInt instead of a datetime or smalldatetime. That simply means
you
have to do a bunch of casting back and forth to get data out of the table.
Another downside to this approach is that it is not obvious to other develop
ers
that this is what you are doing.
2. Use a datetime/smalldatetime and put a check constraint on the table that
requires all values have zero for the time element. That would require that
the
client code strip the time portion before it passes it to the database lest
it
get an error.
3. Use a datetime/smalldatetime and put an Instead Of trigger on the table t
hat
strips the time portion before the value is entered.
4. Let the time portion be stored, but ignore it or strip it for purposes of
retrieval. It does mean you have to be a bit more careful with your queries,
but
it obviously simplifies table structure. In addition, if you are following a
modular design and have all your database calls in a central location, you c
an
strip the time portion in your database calls.
HTH
Thomas
"Hardik Shah" <har_sha_99@.hotmail.com> wrote in message
news:OvHsm9NTFHA.2560@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am new to SQL Server, I am using SQL Server 2000, I want to store only
> date (not time) in my table, is it possible in sql , is there any data typ
es
> except datetime and smalldatetime.
>
> Thanks in advance.
>
> Hardik Shah.
>

Tuesday, February 14, 2012

DateAdd function in Stored Procedure

I need to be able to store a value in a datefield that is 8 hours greater
than another datefield (SchedOpen) which the user updates. What happens is
the user enters local time and I need to also store that time as GMT. I trie
d
this as an alias in a stored procedure: "DATEADD(hh, 8, SchedOpen)" and it
works fine until there is a time when adding 8 hours goes beyond midnight. I
then get a date added to the field which is the year 1900. I suspect that
since the field only contains time the date is defaulted to 1900. There is a
date field in each row with the current date so I need to somehow add that t
o
the GMT field before adding the 8 hours but I just can't figure out how to
do this. Any Ideas? Thanks.Why you need to store it.
you still can access the same field and add the extra 8 hours.
I don't see a problem in adding the hours.
your problem is how to format the date field.
I tried this one
select getdate(),dateadd(hh,8,getdate())
the result was:-
2005-12-07 16:55:13.197 2005-12-08 00:55:13.197
So you can see that I passed the midnight and the and became in a new day.
I still can access the time or the date portions by formating the date.
like in this example:-
select convert(char(8),getdate(),8),convert(cha
r(8),dateadd(hh,8,getdate()),
8)
the result was
17:06:27 01:06:27
I got what I need from the date and i added the hours too.
So all about formating the date.
Thanks,
Nader Shahin
"AkAlan" wrote:

> I need to be able to store a value in a datefield that is 8 hours greater
> than another datefield (SchedOpen) which the user updates. What happens is
> the user enters local time and I need to also store that time as GMT. I tr
ied
> this as an alias in a stored procedure: "DATEADD(hh, 8, SchedOpen)" and i
t
> works fine until there is a time when adding 8 hours goes beyond midnight.
I
> then get a date added to the field which is the year 1900. I suspect that
> since the field only contains time the date is defaulted to 1900. There is
a
> date field in each row with the current date so I need to somehow add that
to
> the GMT field before adding the 8 hours but I just can't figure out how t
o
> do this. Any Ideas? Thanks.
>|||AkAlan (AkAlan@.discussions.microsoft.com) writes:
> I need to be able to store a value in a datefield that is 8 hours
> greater than another datefield (SchedOpen) which the user updates. What
> happens is the user enters local time and I need to also store that time
> as GMT. I tried this as an alias in a stored procedure: "DATEADD(hh, 8,
> SchedOpen)" and it works fine until there is a time when adding 8 hours
> goes beyond midnight. I then get a date added to the field which is the
> year 1900. I suspect that since the field only contains time the date is
> defaulted to 1900. There is a date field in each row with the current
> date so I need to somehow add that to the GMT field before adding the 8
> hours but I just can't figure out how to do this. Any Ideas? Thanks.
There is no time data type in SQL Server (not even in SQL 2005). When you
do not specify a date, the default date is 1900-01-01.
If you want to keep all times within the same date, you will have to
something like:
SELECT convert(datetime, convert(char(8), dateadd(hh, 8, SchedOpen), 108))
or
SELECT dateadd(hh, CASE WHEN SchedOpen < '16:00:00' THEN 8 ELSE -16 END,
SchedOpen)
By the way, in most interfaces you will have to explicitly remove that
date part of 1900-01-01. You may be looking in Enterprise Manager, but
EM is not an application.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks, I did figure out how to add the date field with the time field like
this:
DATEADD(hh, 9, dbo.tblMissions.DateFlown + dbo.tblMtr.StartTime)
This allows me to format the field and present it the way the customer
wants. My real problem is storing the data without have to make design
changes every time we change daylight savings time. I'm using MS Access as
a
front end. Here is the situation...I have a form which the user enters a
local date and time value. I need the report to display the local values as
well as the corresponding GMT based on the local entry. I need to store the
GMT value with each row since I never know on which day the data is being
viewed. I think I'll have to ceate a table and add the daylight savings days
(beging and end) then check the entry date to the table and update the field
with code on the after update event of the local time field. Thanks for your
reply.
"Nader Shahin" wrote:
> Why you need to store it.
> you still can access the same field and add the extra 8 hours.
> I don't see a problem in adding the hours.
> your problem is how to format the date field.
> I tried this one
> select getdate(),dateadd(hh,8,getdate())
> the result was:-
> 2005-12-07 16:55:13.197 2005-12-08 00:55:13.197
> So you can see that I passed the midnight and the and became in a new day.
> I still can access the time or the date portions by formating the date.
> like in this example:-
> select convert(char(8),getdate(),8),convert(cha
r(8),dateadd(hh,8,getdate()
),8)
> the result was
> 17:06:27 01:06:27
> I got what I need from the date and i added the hours too.
> So all about formating the date.
> Thanks,
> Nader Shahin
>
> "AkAlan" wrote:
>