Re: DateTime

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Sep 3, 2:05 pm, Joe Cool <joecool1...@xxxxxxxx> wrote:
On Sep 3, 12:00 pm, shapper <mdmo...@xxxxxxxxx> wrote:

Hello,

On a SQL table I have a Date field.

When I don't set a date field what value is created and that is its
interpretation?

Can I create the date from my C# code using:
DateTime LastLogin = new DateTime();

Basically LastLogin holds the last moment the user has login but if
the user didn't login yet I need to set some date that informs be of
that.

This is what I am looking to determine.

If the SQL Column is set to "NOT NULL", then SQL will not let you
store an empty value. You MUST specify a valid value for the DateTime
datatype, or it simply will not store the row. The value is totally up
to you. If you must content with NOT NULL column, then you will need
to decide what value you may want to use that signal's "no value has
been set yet". Probably the minimum allowed value for the DateTime
datatype.

If the column is defined as "NULL" and you do not specify a value, the
column will contain the null value.

In C#, you can use MinValue() (i.e. DateTime LoginTime =
DateTime.MinValue()). Then later in code you can check for
DateTime.MinValue() as you would check for null, as such:

if(LoginTime == DateTime.MinValue())
{
// Code for no login
}
else
{
// User has logged in at some point
}

As for the database side, typically SQL Server will store the value as
0 (all dates are actually stored behind the scenes as numbers), and
the 0 gets converted to whatever the machine-specific settings for the
minimum date time value. At the last place I worked at, for example, a
DATETIME field that was null was the equivalent of 1/1/1900 I believe.

Mapping between the two may be harder, as you might have to do
something where you store the database min value in a config file, and
then compare it

LoginValue = [code to pull DateTime value from database];
if (LoginValue = Properties.Settings.Default.SQLServerMinDateValue)
{
// code to handle a null/zero
}
.



Relevant Pages

  • Re: help with asp/sql convert data to date for comparison
    ... It must be MS SQL Server ... columns and store proper datetime values in a single column. ... Adjust that until you are creating proper datetimes. ... You should see data in the proper format. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Date: Can you have one that is just mm/dd or mm/yyyy etc?
    ... If so, they are right, just display it with less resolution might be your ticket. ... they were thinking of there was mixed resolutions in one DATETIME column. ... One thing to watch is to NOT take my suggestion and print out everything ... determine if a day exists in it, and build the SQL accordingly. ...
    (comp.lang.java.programmer)
  • Re: Parameter??
    ... in common with most available SQL ... given month' Validation Rule or constraint? ... date_col DATETIME NOT NULL, ... The above relies on the Jet implementation to coerce a DATETIME to ...
    (microsoft.public.access.queries)
  • Re: Parameter??
    ... in common with most available SQL ... given month' Validation Rule or constraint? ... date_col DATETIME NOT NULL, ... The above relies on the Jet implementation to coerce a DATETIME to ...
    (microsoft.public.access.queries)
  • Re: Query Question for the Gurus
    ... datetime as an input parameter and returns the YYYYMMDDHHMM as a string ... select dOctets, myfunc, count ... I'm away from SQL or I could write a small test for you.... ... you could also do datefunctions which return a datetime datatype (rounded to ...
    (microsoft.public.sqlserver.programming)