DateTime Value differ

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gr8Ashish
    New Member
    • Nov 2008
    • 9

    DateTime Value differ

    Hi all,
    I am facing a problem. I create a application that is insert date and time in SQL Server 2005 table from web page then i fetch this datetime type field in vb.net application and adding some hours or minute into it then again update that field

    but the problem is when i insert via web (my .aspx page) it save as different format then the other one same function i use in vb.net application will give me different format in sql server
    i use these-
    .net version 2.0
    my system windows XP regional setting has date format as dd/MMM/yyyy time format as h:mm:ss tt

    sqlserver 2005 table with datetime field

    in my aspx pages i use-
    <font style="color:#0 09900">dim newdt1 as datetime<br>
    newdt1 = Microsoft.Visua lBasic.FormatDa teTime(newdt, DateFormat.Gene ralDate)</font>

    This is inserting date in sql server - 17.11.2008 15:23:54

    after that i select this date in vb.net application project


    <font style="color:#0 09900">dim newdttime as datetime<br>
    ' adding hr and min into current time<br>
    newdttime = Date.Now.Add(Ne w TimeSpan(0, 10, 0))<br>

    newdttime = Microsoft.Visua lBasic.FormatDa teTime(newdttim e, DateFormat.Gene ralDate)</font><br>
    sql server save it as 17/Nov/2008 03:33:26 PM

    <b style="color:#9 90000">My question is that same function is giving me different date format.</b> Why?
  • gr8Ashish
    New Member
    • Nov 2008
    • 9

    #2
    DateTime Value differ

    Hi all,
    I am facing a problem. I create a application that is insert date and time in SQL Server 2005 table from web page then i fetch this datetime type field in vb.net application and adding some hours or minute into it then again update that field

    but the problem is when i insert via web (my .aspx page) it save as different format then the other one same function i use in vb.net application will give me different format in sql server
    i use these-
    .net version 2.0
    my system windows XP regional setting has date format as dd/MMM/yyyy time format as h:mm:ss tt

    sqlserver 2005 table with datetime field

    in my aspx pages i use-
    Code:
    dim newdt1 as datetime
    newdt1 = Microsoft.VisualBasic.FormatDateTime(newdt, DateFormat.GeneralDate)
    This is inserting date in sql server - 17.11.2008 15:23:54

    after that i select this date in vb.net application project


    Code:
    dim newdttime as datetime
    ' adding hr and min into current time
    newdttime = Date.Now.Add(New TimeSpan(0, 10, 0))
    
    newdttime = Microsoft.VisualBasic.FormatDateTime(newdttime, DateFormat.GeneralDate)
    sql server save it as 17/Nov/2008 03:33:26 PM

    [HTML]My question is that same function is giving me different date format. Why?[/HTML]

    Comment

    • gyanendar
      New Member
      • Jun 2007
      • 90

      #3
      SQL server have a default mode of storing date-time field.
      So when we retrive data ,it give us that default format value.

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        while saving datetime field you should specify the format, like ,to dd/mm/yy hh:mm etc... Again while retrieving records you should specfy the format ...The default format will be displayed if you dont specify...
        Datetime

        Comment

        • gr8Ashish
          New Member
          • Nov 2008
          • 9

          #5
          Originally posted by gyanendar
          SQL server have a default mode of storing date-time field.
          So when we retrive data ,it give us that default format value.
          thanks for your reply

          but the problem seems not with sql server it stored whatever it vb code provide it to variable
          at first time - i got sqlserver value in dd.mm.yyy h:mm:ss
          an dwhen update i got sql server value is changed to dd/MMM/yyyy h:mm:ss tt (default format)

          Comment

          • gr8Ashish
            New Member
            • Nov 2008
            • 9

            #6
            Originally posted by DeepBlue
            while saving datetime field you should specify the format, like ,to dd/mm/yy hh:mm etc... Again while retrieving records you should specfy the format ...The default format will be displayed if you dont specify...
            Datetime
            but there is not any retrival of data here
            i insert at first time that automatically takes different format(dd.MM.yy yy h:mm:ss)
            when i update(overload same field) i got different format(dd/MMM/yyyy h:mm:ss tt) - default format

            only change that i use same function Microsoft.Visua lBasic.FormatDa teTime(Date.Now , DateFormat.gene raldate)
            but from different plateform [web(.aspx) and vb application(.vb )]

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              DateTimes are not (assuming you are using DateTime objects and a DateTime columns) stored in any "format". They are stored as a number of seconds since their defined epoch start.
              How the datetime is displayed is based on the format you give it.
              also, try to use .NET conventions such as DateTime.toStri ng("mm/dd/yyyy HH:MM:ss"); instead of using the backwards Microsoft.Visua lBasic library.
              DateFormat.Gene ralDate in combination might not produce the same value.

              Comment

              • rpicilli
                New Member
                • Aug 2008
                • 77

                #8
                Try to format the date before save to the SQL Database Table. This could be a soluction for your issue.

                Another way is before do anything with the data fetched on table, you can verify the format and change to the one expect.

                I hope this help you

                Rpicilli

                Comment

                Working...