Solved

c# .net DateTime without Time

Posted on 2011-03-02
6
458 Views
Last Modified: 2012-05-11
Is there a way of setting a DateTime, and persisting that to SQL Server DateTime field and distinguish between those with times and those without, without using a 'special' time like midnight?
E.g. I want a datetime field to hold NextAppointmentDate, which may or may not have a Time, but I don't want to store a seperate Time field, is that possible?
0
Comment
Question by:Silas2
[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
6 Comments
 
LVL 9

Expert Comment

by:s_chilkury
ID: 35016877
I think this question is in regards of SQL DateTime field.

If you wish to store a date (NextAppointmentDate) then you need to store that in Date field in case of SQL Server 2008. This is not the case with SQL Server 2005 or less. In that case you need to store date field excluding time specifying the time as 00:00:00.
0
 

Author Comment

by:Silas2
ID: 35016939
You can't say 'the time element is null' somehow? Its just that someone might want to use midnight.
0
 
LVL 9

Expert Comment

by:s_chilkury
ID: 35017065
Yes, for SQL Server 2005 or below versions we dont have time element as NULL. But with SQL Server 2008 we have a new datatype which is date and time as separate datatypes.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Jini Jose
ID: 35017125
you can use the datetime field.
and while passing the datetime value from c# you can format it with yyyy-Mm-dd hh:mm:ss.

if it has time then the datetime value will be like this 2011-Mar-03 10:20:33
and if it not has time then the datetime value will be like this 2011-Mar-03 00:00:00

0
 

Author Comment

by:Silas2
ID: 35017898
Yes gmailjini: but that is midnight, isn't it? Say someone wanted to use midnight? wouldn't that get confused with 'time=null'?
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 125 total points
ID: 35022259
The answer is that you need two separate fields in your database to accomplish this, one for Date and one for Time. .Net has no notion of a date-only type.

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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