Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-10
4
Medium Priority
?
53 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 1000 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 1000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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