?
Solved

sql DateTime convert  problem

Posted on 2008-06-16
2
Medium Priority
?
305 Views
Last Modified: 2010-04-21
Hi
I'll simplify my problem , i have table with columm  "Issue_dt" smaldatetime
selct * from mytable
the result appear like the following
Issue_dt
-----------
2008-06-15 00:00:00
2008-06-12 13:49:00
2008-06-12 13:49:00
------------
but when i perform the follwong select
Select issue_dt,convert(nvarchar(10) ,issue_dt ,103) ,convert(nvarchar(10),'2009-08-03 00:00:00:000',103) from MyTable
the result comes as following
-------------------
2008-06-15 00:00:00      15/06/2008      2009-08-03
2008-06-12 13:49:00      12/06/2008      2009-08-03
2008-06-12 13:49:00      12/06/2008      2009-08-03
2008-06-12 13:49:00      12/06/2008      2009-08-03
---------------
my question is why the sql server convert the constant value  '2009-08-03 00:00:00:000'  to  2009-08-03 NOT to 03/08/2008 despite i use the same format in convert function ?
This cause a big problem in my VB.net application  because i sent a parameter to SP  with values like ''2009-08-03 00:00:00:000' to use it in Where condition to compare between the date only that stored in issue_dt column so when i use
convert(nvarchar(10),'2009-08-03 00:00:00:000',103)  it consider it as  2009-08-03 not as 03/08/2008 ? so how can i solve this problem
0
Comment
Question by:ali_alannah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 21794586
that is because your parameter in the third column IS already varchar and not datetime:


Select issue_dt,convert(nvarchar(10) ,issue_dt ,103) ,convert(nvarchar(10), convert(datetime, '2009-08-03 00:00:00:000', 120),103) from MyTable

Open in new window

0
 

Author Closing Comment

by:ali_alannah
ID: 31467651
Ooops !!!:)
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question