Solved

c# .net DateTime without Time

Posted on 2011-03-02
6
453 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
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now