Showing posts with label dateformat. Show all posts
Showing posts with label dateformat. Show all posts

Sunday, February 19, 2012

Dateformat problem in Query Analyser

Hi Everybody,
i have a small problem ?
i have a two different servers
one is used for test purposes and the other one is used for live proposes

i have a table call Employee in both the servers and i got a filed call Attnd_Dttm

so when i open a query analyzer from the test database and type
select * from Employee where convert(datetime,Attnd_Dttm) like '13/01/2005'
i am getting the correct results

but when i am type the same SQL from the live databse
select * from Employee where convert(datetime,Attnd_Dttm) like '13/01/2005'
it give me the
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

My problem is how come this happen ,cos i checked form the live database server computer it's using a British standard date time format like dd/mm/yyyyy ?

Any Idea to solve this problem,cos i need to run the same SQL in both the servers without any problems ?

regards
suis

Try using this date format: 2005-01-13. (year, month, day, dash-separated). This format seems to work in all localizations.

-Ryan / Kardax

|||Hi Ryan
u r reply is not clear to me,
where can i give this command !

is there any command to find out the sql server date time format
regards
suis
|||

I think that you have differenet default DATEFORMAT option on your servers.

You could use SET SET DATEFORMAT 'mdy'

Or use explicit convert:

select * from Employee where convert(datetime,Attnd_Dttm,103) like '13/01/2005'

|||HI Konstantin Kosinsky
Thanks very much for your comments
u r solution is worked out,
but is there any command to check SQL server DateTime fornat ?

regards
suis

|||

suis,

I wonder if you could alter that column a make it datetime data type. If you can not change the data type of that column, I will suggest to store the value using ISO ('yyyymmdd') or ISO8601 ('yyyy-mm-ddThh:miTongue Tieds.mmm'). This way, SQL Server can interpret the string as a datetime no matter the language or formatdate settings.

Code Snippet

set dateformat dmy

go

select cast('2007-05-13T08:15:45.997' as datetime)

go

set dateformat mdy

go

select cast('2007-05-13T08:15:45.997' as datetime)

go

set language Spanish

go

select cast('2007-05-13T08:15:45.997' as datetime)

go

set language English

go

select cast('2007-05-13T08:15:45.997' as datetime)

go

AMB

DateFormat Problem

Hi,

I've gone through various posts related to this topic but did not find the solution.

I have a smalldatetime field in SQLServer and I want to retrieve the value in "dd/mm/yyyy" format.

Below is the code for my formula field:

[Code Start]

IF {ListOfProjectsDeveloperWise.Fld_Invoice_Status} = "No" then

"Not Raised"

else

Left ({ListOfProjectsDeveloperWise.Fld_Invoice_name}, 3) & "-" & Date({ListOfProjectsDeveloperWise.Fld_Invoice_Date})

[Code End]

Fld_Invoice_Date is smalldatetime and i want to retrieve it in dd/mm/yyyy format. It is stored in mm/dd/yyyy format. I have tried various methods like datepart() etc but none yields suitable result.

Regards,

VinayHi

plz try this format

Date (YYYY, MM, DD)
Returns a Date value given numeric arguments of the year, month, and day.

Example :

The following examples are applicable to Crystal syntax:

Date ("Dec 31, 2005")
Returns the Date value for Dec. 31, 2005.

Date (#Oct. 20, 2005 12:02pm#)
Returns the Date value for October 20, 2005.

Date (2005, 7, 30)
Returns the Date value for July 30, 2005.|||No, it doesn't solve the problem.

regards,

Vinay|||Right click on the field and select format field Now you can choose the format you want

dateformat is ignored

Hello,

I receive a file containing some character fields along with a date.
The date values in the file are formatted as "dd/mm/yy", that is
2-digit day, 2-digit month, and 2-digit year. The separator could be
slash or a dash ("-"). The file is in a proprietary format, and bcp is
not an option.

So, I decided to load the file using a prepared statement. I open a
cursor with an INSERT statement, read from the file, parse out values,
and put it in the database using the cursor. All is OK; except that
the date values are mangled. This is despite the fact that I am issuing
a "set dateformat dmy" before running the INSERT statement.

It seems that the "set dateformat dmy" is not being accepted, or it is
being ignored. I set it at the beginning right after opening a
connection to the database. From what I understand, it should work.
Am I doing something wrong? Any suggestions on how to get this to
work?

Thanks!newtophp2000@.yahoo.com wrote:

> Hello,
> I receive a file containing some character fields along with a date.
> The date values in the file are formatted as "dd/mm/yy", that is
> 2-digit day, 2-digit month, and 2-digit year. The separator could be
> slash or a dash ("-"). The file is in a proprietary format, and bcp is
> not an option.
> So, I decided to load the file using a prepared statement. I open a
> cursor with an INSERT statement, read from the file, parse out values,
> and put it in the database using the cursor. All is OK; except that
> the date values are mangled. This is despite the fact that I am issuing
> a "set dateformat dmy" before running the INSERT statement.
> It seems that the "set dateformat dmy" is not being accepted, or it is
> being ignored. I set it at the beginning right after opening a
> connection to the database. From what I understand, it should work.
> Am I doing something wrong? Any suggestions on how to get this to
> work?
> Thanks!

You say BCP isn't an option but you didn't explain what other method
you are using to read the file or why a cursor is necessary. Don't rely
on SET DATEFORMAT. Use the CONVERT function with the style parameter to
specify the exact format. Looks like style 3 or 103 is what you need.

--
David Portas
SQL Server MVP
--|||David Portas wrote:
> You say BCP isn't an option but you didn't explain what other method
> you are using to read the file or why a cursor is necessary. Don't rely
> on SET DATEFORMAT. Use the CONVERT function with the style parameter to
> specify the exact format. Looks like style 3 or 103 is what you need.

I read from the file line by line and parse the line to extract the
fields. I then use the bound variables in the prepared Insert
statement to add it to the database. I wanted to change the DATEFORMAT
configuration as it seemed to be such a straight answer. I guess I
could use the CONVERT function if it is fast enough. I can do some
tests to see how it performs.

I am curius: is there a particular reason to shy away from setting
DATEFORMAT? Is it not reliable as implemented or something else?

Thanks a lot!

> --
> David Portas
> SQL Server MVP
> --|||Hi

If you are parsing a string then you constructing the date in CCYYMMDD
format will be a safe option.

John

<newtophp2000@.yahoo.com> wrote in message
news:1135777730.480129.321010@.z14g2000cwz.googlegr oups.com...
> David Portas wrote:
>> You say BCP isn't an option but you didn't explain what other method
>> you are using to read the file or why a cursor is necessary. Don't rely
>> on SET DATEFORMAT. Use the CONVERT function with the style parameter to
>> specify the exact format. Looks like style 3 or 103 is what you need.
>
> I read from the file line by line and parse the line to extract the
> fields. I then use the bound variables in the prepared Insert
> statement to add it to the database. I wanted to change the DATEFORMAT
> configuration as it seemed to be such a straight answer. I guess I
> could use the CONVERT function if it is fast enough. I can do some
> tests to see how it performs.
> I am curius: is there a particular reason to shy away from setting
> DATEFORMAT? Is it not reliable as implemented or something else?
> Thanks a lot!
>
>> --
>> David Portas
>> SQL Server MVP
>> --|||David and John,

Thank you very much for your input. I am now using the techniques that
you suggested and it works great!

DateFormat

I have a column of effDate, its format likes this 2004-05-04 11:37:26.783, I
need get data from effData is 2004-05-04.
How do I trunc effDate to yyyy-mm-dd format. I just started to learn TSQL.
Thanks for your help
SELECT CONVERT(CHAR(10), effDate, 23) FROM <tablename>
http://www.aspfaq.com/
(Reverse address to reply.)
"Sally" <Sally@.discussions.microsoft.com> wrote in message
news:05CDD692-5B69-45B5-B9CE-86FE97D76C5F@.microsoft.com...
> I have a column of effDate, its format likes this 2004-05-04 11:37:26.783,
I
> need get data from effData is 2004-05-04.
> How do I trunc effDate to yyyy-mm-dd format. I just started to learn TSQL.
> Thanks for your help
|||What is the datatype for the column? If it is datetime or smalldatetime, then you either need to format it in
the client application, or return as a string, using the CONVERT function and specify a suitable format code
for the 3:rd parameter of that function. This and more, you can read in:
http://www.karaszi.com/SQLServer/info_datetime.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Sally" <Sally@.discussions.microsoft.com> wrote in message
news:05CDD692-5B69-45B5-B9CE-86FE97D76C5F@.microsoft.com...
> I have a column of effDate, its format likes this 2004-05-04 11:37:26.783, I
> need get data from effData is 2004-05-04.
> How do I trunc effDate to yyyy-mm-dd format. I just started to learn TSQL.
> Thanks for your help

dateformat

Hi every body
I am using a stored procedure to insert values into a table which contain a date datatype. I pass the date in MM-DD-YYYY format.
When i execute the querry it shows error invalid month.

create or replace procedure sample_I
(
P_no varchar2,
P_date date
)
as
begin
insert into sample values(P_no ,to_date(P_date,'MM-DD-YYYY' ));
end;Since p_date already is a date, you should not apply the TO_DATE function to it - doing so is the cause of your problem. Code should be:
create or replace procedure sample_I
(
P_no varchar2,
P_date date
)
as
begin
insert into sample values(P_no ,P_date);
end;
BTW, since this question is Oracle-specific, it would have got answered quicker if you had posted it in the Oracle forum!

DateFormat

I have a column of effDate, its format likes this 2004-05-04 11:37:26.783, I
need get data from effData is 2004-05-04.
How do I trunc effDate to yyyy-mm-dd format. I just started to learn TSQL.
Thanks for your helpSELECT CONVERT(CHAR(10), effDate, 23) FROM <tablename>
http://www.aspfaq.com/
(Reverse address to reply.)
"Sally" <Sally@.discussions.microsoft.com> wrote in message
news:05CDD692-5B69-45B5-B9CE-86FE97D76C5F@.microsoft.com...
> I have a column of effDate, its format likes this 2004-05-04 11:37:26.783,
I
> need get data from effData is 2004-05-04.
> How do I trunc effDate to yyyy-mm-dd format. I just started to learn TSQL.
> Thanks for your help|||What is the datatype for the column? If it is datetime or smalldatetime, the
n you either need to format it in
the client application, or return as a string, using the CONVERT function an
d specify a suitable format code
for the 3:rd parameter of that function. This and more, you can read in:
http://www.karaszi.com/SQLServer/info_datetime.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Sally" <Sally@.discussions.microsoft.com> wrote in message
news:05CDD692-5B69-45B5-B9CE-86FE97D76C5F@.microsoft.com...
> I have a column of effDate, its format likes this 2004-05-04 11:37:26.783,
I
> need get data from effData is 2004-05-04.
> How do I trunc effDate to yyyy-mm-dd format. I just started to learn TSQL.
> Thanks for your help

DateFormat

Hi all
Whenever I use the cOnvert function to convert the date
format to other format I always get the same format of
date.
eg:
For the date '2003-12-02 09:00:00.000'
I use select convert(datetime,ShiftStartTime,126)
still getting the same output as
'2003-12-02 09:00:00.000'
but supposed to be in the format dd/mm/yy hh:mi:ss:mmmAM
as per BOL.
Please carify.
Thanks in advance
Anand.Internally, SQL stores the date with all the information it needs. You are
converting a DateTime to DateTime, if you want to display it in a certain
format, you have to use:
convert(NCHAR(23),ShiftStartTime,126)
This converts it to a string that is formatted how you want it.
--
--
Mike Epprecht, Microsoft SQL Server MVP
Epprecht Consulting (PTY) LTD
Johannesburg, South Africa
Mobile: +27-82-552-0268
IM: mike@.NOSPAMepprecht.net
Specialist SQL Server Solutions and Consulting
"Anand" <gurusanand@.yahoo.com> wrote in message
news:01f501c3d685$fa191c90$a001280a@.phx.gbl...
> Hi all
> Whenever I use the cOnvert function to convert the date
> format to other format I always get the same format of
> date.
> eg:
> For the date '2003-12-02 09:00:00.000'
> I use select convert(datetime,ShiftStartTime,126)
> still getting the same output as
> '2003-12-02 09:00:00.000'
> but supposed to be in the format dd/mm/yy hh:mi:ss:mmmAM
> as per BOL.
> Please carify.
> Thanks in advance
> Anand.
>|||The problem is that you needed to convert the date to a char or varchar, not
datetime...
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Anand" <gurusanand@.yahoo.com> wrote in message
news:01f501c3d685$fa191c90$a001280a@.phx.gbl...
> Hi all
> Whenever I use the cOnvert function to convert the date
> format to other format I always get the same format of
> date.
> eg:
> For the date '2003-12-02 09:00:00.000'
> I use select convert(datetime,ShiftStartTime,126)
> still getting the same output as
> '2003-12-02 09:00:00.000'
> but supposed to be in the format dd/mm/yy hh:mi:ss:mmmAM
> as per BOL.
> Please carify.
> Thanks in advance
> Anand.
>

DateFormat

How to a format a date u appear as short month.
I.e. i want to see it like this Apr/27/2005
ThanksIn the Properties/format of the textbox , go to Custom and type MMM"/"dd"/
"yyyy
Hope this helps
Ramani
"Fab" wrote:
> How to a format a date u appear as short month.
> I.e. i want to see it like this Apr/27/2005
> Thanks
>
>|||It doesn't help. Do you have any idea.
thanks
From http://www.developmentnow.com/g/115_2005_6_0_0_551901/DateFormat.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com|||Use MMM/dd/yyyy without the quotes. I know it works.
"meera" wrote:
> It doesn't help. Do you have any idea.
> thanks.
> From http://www.developmentnow.com/g/115_2005_6_0_0_551901/DateFormat.htm
> Posted via DevelopmentNow.com Groups
> http://www.developmentnow.com
>

Dateformat

How can I determine current
SET DATEFORMAT ?DBCC USEROPTIONS
Martin C K Poon
Senior Analyst Programmer
====================================
"Alur" <Alur@.discussions.microsoft.com> bl
news:D2C70A61-AD21-4EFE-A945-5A7A72EBF6B7@.microsoft.com g...
> How can I determine current
> SET DATEFORMAT ?|||If you haven't localized SQL Server for your language, the default date
format is the American one: DD/MM/YY.
Use
SELECT GETDATE() and this will show you the default currently.
"Alur" wrote:

> How can I determine current
> SET DATEFORMAT ?|||> SELECT GETDATE() and this will show you the default currently.
No, the presentation of datetime has no correlation of how input of datetime
strings are
interpreted. See http://www.karaszi.com/SQLServer/info_datetime.asp for more
information.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Derekman" <Derekman@.discussions.microsoft.com> wrote in message
news:23BB0F57-2A93-4E20-95C8-7E5038756D51@.microsoft.com...
> If you haven't localized SQL Server for your language, the default date
> format is the American one: DD/MM/YY.
> Use
> SELECT GETDATE() and this will show you the default currently.
> "Alur" wrote:
>|||Sorry, Derekman, but this is not correct.
The American format, the default, is MDY.
Also, GETDATE() has nothing to do with DATEFORMAT.
DATEFORMAT shows you how SQL Server interprets incoming strings as dates.
For example, if you ask it to convert '3/4/06' to a datetime, will it be
April 3rd or March 4th?
SELECT CONVERT(datetime, '3/4/06')
DATEFORMAT tells SQL Server how to interpret a string that has all numbers,
which number is the month,
which is day and which is year. For the default MDY, it means the first
number is month, so '3/4/06' would be March 4th.
GETDATE returns the current date and time in a default output format, which
is based on your regional settings.
To DISPLAY a datetime in another format, you need to convert it to a string,
and specify a style. You can see the different styles available if you read
about CONVERT in the Books Online.
HTH
Kalen Delaney, SQL Server MVP
"Derekman" <Derekman@.discussions.microsoft.com> wrote in message
news:23BB0F57-2A93-4E20-95C8-7E5038756D51@.microsoft.com...
> If you haven't localized SQL Server for your language, the default date
> format is the American one: DD/MM/YY.
> Use
> SELECT GETDATE() and this will show you the default currently.
> "Alur" wrote:
>|||DBCC USEROPTIONS
Another solution is to write some code similar to this:
SET DATEFORMAT ydm
GO
DECLARE @.datevar datetime
SET @.datevar = '01/02/03'
SELECT cast(datepart(month,@.datevar)as char(1))
+ cast(datepart(day,@.datevar)as char(1))
SELECT case cast(datepart(month,@.datevar)as char(1))
+ cast(datepart(day,@.datevar)as char(1))
when 31 then 'dym'
when 21 then 'dmy'
when 12 then 'mdy'
when 13 then 'myd'
when 32 then 'ydm'
when 23 then 'ymd'
else '?'
end
"Alur" wrote:

> How can I determine current
> SET DATEFORMAT ?|||Hi Greg
This is a really solution! I hope you don't mind that I cleaned it up
just a bit:
SET DATEFORMAT ydm; -- For testing
GO
DECLARE @.datevar datetime,
@.datecode char(2);
SET @.datevar = '01/02/03'
SELECT @.datecode = cast(datepart(month,@.datevar)as char(1))
+ cast(datepart(day,@.datevar)as char(1));
SELECT @.datecode AS datecode; -- For troubleshooting
SELECT CASE @.datecode
when '31' then 'dym'
when '21' then 'dmy'
when '12' then 'mdy'
when '13' then 'myd'
when '32' then 'ydm'
when '23' then 'ymd'
else '?'
END AS DATEFORMAT;
HTH
Kalen Delaney, SQL Server MVP
"Greg Larsen" <GregLarsen@.discussions.microsoft.com> wrote in message
news:E90E6795-5952-4D4F-AAB5-00B764EB5130@.microsoft.com...
> DBCC USEROPTIONS
> Another solution is to write some code similar to this:
> SET DATEFORMAT ydm
> GO
> DECLARE @.datevar datetime
> SET @.datevar = '01/02/03'
> SELECT cast(datepart(month,@.datevar)as char(1))
> + cast(datepart(day,@.datevar)as char(1))
> SELECT case cast(datepart(month,@.datevar)as char(1))
> + cast(datepart(day,@.datevar)as char(1))
> when 31 then 'dym'
> when 21 then 'dmy'
> when 12 then 'mdy'
> when 13 then 'myd'
> when 32 then 'ydm'
> when 23 then 'ymd'
> else '?'
> end
> "Alur" wrote:
>|||No problem on the clean up. New script is much better.
"Kalen Delaney" wrote:

> Hi Greg
> This is a really solution! I hope you don't mind that I cleaned it up
> just a bit:
> SET DATEFORMAT ydm; -- For testing
> GO
> DECLARE @.datevar datetime,
> @.datecode char(2);
> SET @.datevar = '01/02/03'
> SELECT @.datecode = cast(datepart(month,@.datevar)as char(1))
> + cast(datepart(day,@.datevar)as char(1));
> SELECT @.datecode AS datecode; -- For troubleshooting
> SELECT CASE @.datecode
> when '31' then 'dym'
> when '21' then 'dmy'
> when '12' then 'mdy'
> when '13' then 'myd'
> when '32' then 'ydm'
> when '23' then 'ymd'
> else '?'
> END AS DATEFORMAT;
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
> "Greg Larsen" <GregLarsen@.discussions.microsoft.com> wrote in message
> news:E90E6795-5952-4D4F-AAB5-00B764EB5130@.microsoft.com...
>
>|||Thank you very much.|||Thank you.