Simple SQL Date Formula

I have searched for literally five hours and cannot find such a simple thing.
I am creating an SQL database and want to put in a column formula for both a date and a time field (both defined datetime).
I need one to be the date in yyyy/mm/dd format and one to be mm/dd/yyyy hh/mm format.
I've tried putting in the above (I know that minutes are nn) "yyyy/mm/dd" & "mm/dd/yyyy hh/nn"  respectively but it gives the error "Error validating the formula for column 'TDate'".
I feel like this is the most ridiculous qustion I've ever asked.
dcassAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
The reason you can't find it is because it doesn't exist.  You are confusing format with data.  The database stores the data... you can pull it into a format if you like but the best way to do this is in an application not in the DB.  SQL does not have a date-only or a time-only datatype.  A datetime is stored as 2 4-byte integer values with one representing the number of days since 1/1/1900 and the other representing the number of milliseconds (more or less) since midnight.  If you give a more detailed example of what you are trying to accomplish then I can get more precise.
0
dcassAuthor Commented:
I know SQL doesn't have a date-only or time-only datatype, but you can put it in different formats by setiing the column format, can't you?  It doesn't have to be in mm/dd/yyyy - I know you can change it in the code, I was just looking for an automatic switch from mm/dd/yyyy to yyyy/mm/dd and thought I could use column format.
0
dcassAuthor Commented:
If you can't do it that way, how do you switch the date in C# from mm/dd/yyyy to yyyy/mm/dd?
Should I store the first field that I want just the date in as a varchar?  How do I strip off the time?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Brian CroweDatabase AdministratorCommented:
It's stored the same no matter how you put it in as long as it is a valid datetime.  If you want to display it in different formats then you can use the Convert function

SELECT Convert(varchar, TDate, 101) --for mm/dd/yyyy
            Convert(varchar, TDate, 111) --for yy/mm/dd

Check out Convert in BOL for different formats
0
Brian CroweDatabase AdministratorCommented:
I'm not sure about C# but in VB.Net i would do something like

myDate.tostring("mm/dd/yyyy") if myDate is a datetime or
CDate(myDateString).tostring("mm/dd/yyyy") if i'm dealing with a date in string form.
0
dcassAuthor Commented:
Also, I want to run a 24 hour clock and not use am/pm.  Is it possible to store it that way so it sorts correctly?
0
Brian CroweDatabase AdministratorCommented:
You're still confusing storage value and format.  I'm sure that in C# you can create a custom format just like you can in VB.Net to apply to the control where you want to format the value.

dim strFormat1 as string = "yyyy/mm/dd HH:mm"
dim strFormat2 as string = "mm/dd/yyyy"

textbox1.text = CDate(myDatatable.rows(0).item("TDate")).tostring(strFormat1)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.