Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Date and Time

Date and Time

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    Hello, I have to insert a current date and current time into a database. I am using vb 2005 and sql 2005. Dim time As DateTime Dim day As DateTime time = Date.Now.ToShortTimeString() day = Date.Now.ToShortDateString() I am using the above to get the time and the day. I would like to display the date as 1/11/2006 and the time as 10:08. However, in the database it is showing as: Date: 10/31/2006 12:00:00 AM Time: 10/31/2006 9:34:11 PM I have set the database field to nvarchar(50). I can't have the fields as dateTime, as I don't want to display a pop calandar in my ultragrid. Is there a problem with the code? Thanks in advance, Steve

    J G 2 Replies Last reply
    0
    • S steve_rm

      Hello, I have to insert a current date and current time into a database. I am using vb 2005 and sql 2005. Dim time As DateTime Dim day As DateTime time = Date.Now.ToShortTimeString() day = Date.Now.ToShortDateString() I am using the above to get the time and the day. I would like to display the date as 1/11/2006 and the time as 10:08. However, in the database it is showing as: Date: 10/31/2006 12:00:00 AM Time: 10/31/2006 9:34:11 PM I have set the database field to nvarchar(50). I can't have the fields as dateTime, as I don't want to display a pop calandar in my ultragrid. Is there a problem with the code? Thanks in advance, Steve

      J Offline
      J Offline
      Janani Divya
      wrote on last edited by
      #2

      Use Like this: Declaration Dim time As DateTime Dim day As DateTime Private culture As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("hi-IN") -------------------- time = Date.Now.ToShortTimeString() day = Date.Now.ToShortDateString() Dim temp As String = Convert.ToDateTime(time, culture) Dim var As String = Convert.ToDateTime(day, culture) This will convert the date and time into Indian culture. temp will have the value of 9:30:00 AM and var will have the value of 11/1/2006 Hope u will got it.

      Janani

      1 Reply Last reply
      0
      • S steve_rm

        Hello, I have to insert a current date and current time into a database. I am using vb 2005 and sql 2005. Dim time As DateTime Dim day As DateTime time = Date.Now.ToShortTimeString() day = Date.Now.ToShortDateString() I am using the above to get the time and the day. I would like to display the date as 1/11/2006 and the time as 10:08. However, in the database it is showing as: Date: 10/31/2006 12:00:00 AM Time: 10/31/2006 9:34:11 PM I have set the database field to nvarchar(50). I can't have the fields as dateTime, as I don't want to display a pop calandar in my ultragrid. Is there a problem with the code? Thanks in advance, Steve

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        steve_rm wrote:

        I can't have the fields as dateTime, as I don't want to display a pop calandar in my ultragrid.

        Don't let limitations like that mess up your database design. Store the datetime properly in the database, and convert it to strings when you are fetching data to be used with that component.

        steve_rm wrote:

        Is there a problem with the code?

        You have been "helped" by VB to convert the values back to DateTime. The extra conversions that are added, as you are storing the values in DateTime variables, are equivalent to: time = Convert.ToDateTime(Date.Now.ToShortTimeString()) day = Convert.ToDateTime(Date.Now.ToShortDateString()) A DateTime structure always has a date and a time, and no information about formatting. If you convert a string containing only a date to a DateTime, it will get the time 0:00. If you convert a string containing only a time, it will get the current date.

        --- b { font-weight: normal; }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups