Solved

How to store a date field in format mm/dd/yyyy into a SQL Server 2008 table?

Posted on 2016-10-10
4
42 Views
Last Modified: 2016-10-10
I am using SQL Server 2008.

If I pass a date value in format "mm/dd/yyyy" as a parameter into a date field titled DateInput within a table named tblDate, is there a way to store this value in this format into this SQL Server table?
0
Comment
Question by:zimmer9
[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
4 Comments
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41837299
If you store the value in a column of data type string then yes. If you store it as a Date, DateTime, or DateTime2 data type then no. However you can format the data on the way out. Your SELECT query would look something like this:
SELECT
  CONVERT(VARCHAR, DateInput, 103) as [DateInput]
FROM
  tblDate

Open in new window

0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 41837304
>is there a way to store this value in this format into this SQL Server table?
No.  Dates are stored as a double number, and not in any specific cosmetic format such as mm/dd/yyyy.

I also wouldn't recommend storing dates as char/varchar's as well, as doing so would reflect character sorting and not date sorting, and you would still have to convert it back to a date format in order to do date specific functions such as DATEADD, DATEPART, DATEDIFF.

>table named tblDate
Tell us more about this tblDate.  I have my own tblDate article you can read called SQL Server Calendar Table, and what you're looking for may be in there.
0
 
LVL 20

Assisted Solution

by:Russ Suter
Russ Suter earned 250 total points
ID: 41837307
Be warned, using a CONVERT statement in a SQL query can reduce performance. This is not something you should normally be doing in SQL. Conversions like this should be in the business logic layer of your application. However, if you need it then the SQL query provided will give you a formatted string as you desire.
0
 

Author Comment

by:zimmer9
ID: 41837322
I think you meant 101 but I understand. Thanks.  :)
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this article I will describe the Detach & Attach 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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
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…

623 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