Solved

sql DateTime convert  problem

Posted on 2008-06-16
2
303 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 500 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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