473,700 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1278
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.ToLongDateSt ring (rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message
news:39******** *************** ***********@mic rosoft.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.ToLongDateSt ring (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***@discussi ons.microsoft.c om> wrote in message
news:39******** *************** ***********@mic rosoft.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.ToDate Time("4/13/2005")).ToLongD ateString)

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.ToLongDateSt ring (rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message
news:39******** *************** ***********@mic rosoft.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.ToDateT ime("13/4/2005")).ToLongD ateString

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***@discussi ons.microsoft.c om> wrote in message
news:2D******** *************** ***********@mic rosoft.com...
Hi,
When I try

New SqlParameter("@ date",
(Convert.ToDate Time("4/13/2005")).ToLongD ateString)

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.ToLongDateSt ring
(rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message
news:39******** *************** ***********@mic rosoft.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.ToDate Time(sDtae)).To LongDateString)
End Sub
And I am calling it like this

GetReport(txtDa te.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.ToDateT ime("13/4/2005")).ToLongD ateString

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***@discussi ons.microsoft.c om> wrote in message
news:2D******** *************** ***********@mic rosoft.com...
Hi,
When I try

New SqlParameter("@ date",
(Convert.ToDate Time("4/13/2005")).ToLongD ateString)

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.ToLongDateSt ring
(rather
then the ShortDateString you are currently sending).

"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message
news:39******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
This is my setup

Private Sub GetReport(ByVal sDate As String)

....New SqlParameter("@ date",
(Convert.ToDate Time(sDtae)).To LongDateString)
End Sub
And I am calling it like this

GetReport(txtDa te.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.ToDateT ime("13/4/2005")).ToLongD ateString

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***@discussi ons.microsoft.c om> wrote in message
news:2D******** *************** ***********@mic rosoft.com...
> Hi,
> When I try
>
> New SqlParameter("@ date",
> (Convert.ToDate Time("4/13/2005")).ToLongD ateString)
>
> 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.ToLongDateSt ring
>> (rather
>> then the ShortDateString you are currently sending).
>>
>> "Chris" <Ch***@discussi ons.microsoft.c om> wrote in message
>> news:39******** *************** ***********@mic rosoft.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
2178
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
9872
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 ********************************** package Celcom.Client;
6
6324
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, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
5
2189
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: Objectives The purpose of this assignment is to have you practice the design of object-oriented classes, including one or more of the following concepts
34
7312
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
48
3233
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 "huge" Indy is both as a project, in support, development, and use. But Indy is new to the .net world. Indy is a HUGE library implementing over 120 internet protocols and standards and comes with complete source. Its an open source project, but not...
8
2744
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 the sequence nos and it should be such that i can access it through the structure .plz help me .
0
3953
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 Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
20
4272
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 is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
0
8645
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9075
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7810
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5903
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.