473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I need some help here

Hi,
I am storing dates in sql server in this format

2005-04-13 22:22:16.353

My asp.net app is passing the date as string like this 4/13/2005

to the foll sp

create proc test(
@date varchar(11))

as
begin

select name from table
where
LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date

but that doesn't work only if I pass it as 2005-04-13 22:22:16.353. I tested
the proc in sql server

exec test '4/13/2005' but this doesn't work.

exec test '2005-04-14' this works.

Please advice.

Thanks
Saif
Nov 19 '05 #1
6 1267
You need to pass the date as a date rather than a varchar, so the procedure
would look more like:

create proc test(
@date datetime)

as
begin

select name from table
where
DateEnt = @date

And I would also suggest you change the date to a long date string in the
..NET part, so if you have a date object dt send dt.ToLongDateString (rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hi,
I am storing dates in sql server in this format

2005-04-13 22:22:16.353

My asp.net app is passing the date as string like this 4/13/2005

to the foll sp

create proc test(
@date varchar(11))

as
begin

select name from table
where
LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date

but that doesn't work only if I pass it as 2005-04-13 22:22:16.353. I
tested
the proc in sql server

exec test '4/13/2005' but this doesn't work.

exec test '2005-04-14' this works.

Please advice.

Thanks
Saif

Nov 19 '05 #2
Joseph Byrns wrote:
You need to pass the date as a date rather than a varchar, so the procedure
would look more like:

create proc test(
@date datetime)

as
begin

select name from table
where
DateEnt = @date

And I would also suggest you change the date to a long date string in the
.NET part, so if you have a date object dt send dt.ToLongDateString (rather
then the ShortDateString you are currently sending).

If you use parameters to call that sp, then you can just use
a DateTime value. No need to convert to string.

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hi,
I am storing dates in sql server in this format

2005-04-13 22:22:16.353

My asp.net app is passing the date as string like this 4/13/2005
to the foll sp
the *debugger* is *displaying* the DateTime value as mm/dd/yyyy,
it doesn't store it internally as string.

create proc test(
@date varchar(11))

as
begin

select name from table
where
LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date

but that doesn't work only if I pass it as 2005-04-13 22:22:16.353. I
tested
the proc in sql server

exec test '4/13/2005' but this doesn't work.

exec test '2005-04-14' this works.

Please advice.

Thanks
Saif


--
Hans Kesting
Nov 19 '05 #3
Hi,
When I try

New SqlParameter("@date", (Convert.ToDateTime("4/13/2005")).ToLongDateString)

I get the error

Error onverting datatype nvarchar to datetime.

"Joseph Byrns" wrote:
You need to pass the date as a date rather than a varchar, so the procedure
would look more like:

create proc test(
@date datetime)

as
begin

select name from table
where
DateEnt = @date

And I would also suggest you change the date to a long date string in the
..NET part, so if you have a date object dt send dt.ToLongDateString (rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hi,
I am storing dates in sql server in this format

2005-04-13 22:22:16.353

My asp.net app is passing the date as string like this 4/13/2005

to the foll sp

create proc test(
@date varchar(11))

as
begin

select name from table
where
LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date

but that doesn't work only if I pass it as 2005-04-13 22:22:16.353. I
tested
the proc in sql server

exec test '4/13/2005' but this doesn't work.

exec test '2005-04-14' this works.

Please advice.

Thanks
Saif


Nov 19 '05 #4
That's because it is getting the American and European dates mixed up, if
you do:

Convert.ToDateTime("13/4/2005")).ToLongDateString

it will work fine. Or you can do as Hans suggested and enter it as a date
object in the parameter.
New SqlParameter("@date", aDateObject)
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,
When I try

New SqlParameter("@date",
(Convert.ToDateTime("4/13/2005")).ToLongDateString)

I get the error

Error onverting datatype nvarchar to datetime.

"Joseph Byrns" wrote:
You need to pass the date as a date rather than a varchar, so the
procedure
would look more like:

create proc test(
@date datetime)

as
begin

select name from table
where
DateEnt = @date

And I would also suggest you change the date to a long date string in the
..NET part, so if you have a date object dt send dt.ToLongDateString
(rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
> Hi,
> I am storing dates in sql server in this format
>
> 2005-04-13 22:22:16.353
>
> My asp.net app is passing the date as string like this 4/13/2005
>
> to the foll sp
>
>
>
> create proc test(
> @date varchar(11))
>
> as
> begin
>
> select name from table
> where
> LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date
>
> but that doesn't work only if I pass it as 2005-04-13 22:22:16.353. I
> tested
> the proc in sql server
>
> exec test '4/13/2005' but this doesn't work.
>
> exec test '2005-04-14' this works.
>
> Please advice.
>
> Thanks
> Saif


Nov 19 '05 #5
This is my setup

Private Sub GetReport(ByVal sDate As String)

.....New SqlParameter("@date",
(Convert.ToDateTime(sDtae)).ToLongDateString)
End Sub
And I am calling it like this

GetReport(txtDate.text)
txtDate receives the date in the format 4/13/2005

This doesn't work.

"Joseph Byrns" wrote:
That's because it is getting the American and European dates mixed up, if
you do:

Convert.ToDateTime("13/4/2005")).ToLongDateString

it will work fine. Or you can do as Hans suggested and enter it as a date
object in the parameter.
New SqlParameter("@date", aDateObject)
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,
When I try

New SqlParameter("@date",
(Convert.ToDateTime("4/13/2005")).ToLongDateString)

I get the error

Error onverting datatype nvarchar to datetime.

"Joseph Byrns" wrote:
You need to pass the date as a date rather than a varchar, so the
procedure
would look more like:

create proc test(
@date datetime)

as
begin

select name from table
where
DateEnt = @date

And I would also suggest you change the date to a long date string in the
..NET part, so if you have a date object dt send dt.ToLongDateString
(rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
> Hi,
> I am storing dates in sql server in this format
>
> 2005-04-13 22:22:16.353
>
> My asp.net app is passing the date as string like this 4/13/2005
>
> to the foll sp
>
>
>
> create proc test(
> @date varchar(11))
>
> as
> begin
>
> select name from table
> where
> LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date
>
> but that doesn't work only if I pass it as 2005-04-13 22:22:16.353. I
> tested
> the proc in sql server
>
> exec test '4/13/2005' but this doesn't work.
>
> exec test '2005-04-14' this works.
>
> Please advice.
>
> Thanks
> Saif


Nov 19 '05 #6
Yes, it is just that the date is the wrong way round (mm/dd/yyyy instead of
dd/mm/yyyy), presumably, txtDate is a text box, can you not use a
DateTimePicker instead? Or drop down lists for the date, that way you can
ensure the date is in the correct order before you start?

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
This is my setup

Private Sub GetReport(ByVal sDate As String)

....New SqlParameter("@date",
(Convert.ToDateTime(sDtae)).ToLongDateString)
End Sub
And I am calling it like this

GetReport(txtDate.text)
txtDate receives the date in the format 4/13/2005

This doesn't work.

"Joseph Byrns" wrote:
That's because it is getting the American and European dates mixed up, if
you do:

Convert.ToDateTime("13/4/2005")).ToLongDateString

it will work fine. Or you can do as Hans suggested and enter it as a
date
object in the parameter.
New SqlParameter("@date", aDateObject)
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
> Hi,
> When I try
>
> New SqlParameter("@date",
> (Convert.ToDateTime("4/13/2005")).ToLongDateString)
>
> I get the error
>
> Error onverting datatype nvarchar to datetime.
>
> "Joseph Byrns" wrote:
>
>> You need to pass the date as a date rather than a varchar, so the
>> procedure
>> would look more like:
>>
>> create proc test(
>> @date datetime)
>>
>> as
>> begin
>>
>> select name from table
>> where
>> DateEnt = @date
>>
>> And I would also suggest you change the date to a long date string in
>> the
>> ..NET part, so if you have a date object dt send dt.ToLongDateString
>> (rather
>> then the ShortDateString you are currently sending).
>>
>> "Chris" <Ch***@discussions.microsoft.com> wrote in message
>> news:39**********************************@microsof t.com...
>> > Hi,
>> > I am storing dates in sql server in this format
>> >
>> > 2005-04-13 22:22:16.353
>> >
>> > My asp.net app is passing the date as string like this 4/13/2005
>> >
>> > to the foll sp
>> >
>> >
>> >
>> > create proc test(
>> > @date varchar(11))
>> >
>> > as
>> > begin
>> >
>> > select name from table
>> > where
>> > LEFT( CONVERT(varchar, DateEnt, 120), 10)= @date
>> >
>> > but that doesn't work only if I pass it as 2005-04-13 22:22:16.353.
>> > I
>> > tested
>> > the proc in sql server
>> >
>> > exec test '4/13/2005' but this doesn't work.
>> >
>> > exec test '2005-04-14' this works.
>> >
>> > Please advice.
>> >
>> > Thanks
>> > Saif
>>
>>
>>


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
5
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows:...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.