locked
DateTime in SQLdb sets date and not the time RRS feed

  • Question

  • User57689994 posted

    Hello,

    Small problem: I have a method that saves a loggingrecord  with a DateTime (dateLogged).

     public void SaveSysLogging(string username, string description, string type)
            {
                if (string.IsNullOrEmpty(username)) username = HttpContext.Current.User.Identity.Name;
                Sys_Logging sl = new Sys_Logging
                                     {
                                         userId = username,
                                         DateLogged = DateTime.Now,
                                         IP = HttpContext.Current.Request.UserHostAddress,
                                         description = description,
                                         type = type
    
    
                                     };
                _db.Sys_Loggings.InsertOnSubmit(sl);
                _db.SubmitChanges();
    
            }

    The DateLogged is set as 24-05-2011 00:00:00 in the DB... WHY?

    I want it to be: 24-05-2011 16:28:13....

    Any help?

    R.

    Tuesday, May 24, 2011 10:30 AM

Answers

  • User57689994 posted

    Okay Cry...

    WHY is the Server Data Type different from the Type???

    Changing the Server Data Type from Date to DateTime helped...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 24, 2011 10:46 AM

All replies

  • User57689994 posted

    Okay Cry...

    WHY is the Server Data Type different from the Type???

    Changing the Server Data Type from Date to DateTime helped...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 24, 2011 10:46 AM
  • User-330204900 posted

    It's just one of those things SQL datetime is different from .Net DataTime and from your code you are using SQL Server 2008 and the Date wich is the date only part of date time.

    Tuesday, May 24, 2011 10:56 AM