Results 1 to 11 of 11

Thread: [2008] date issue

  1. #1

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    [2008] date issue

    hi i am using vb.net 2008 and access
    i want the date to b stored in dd/MM/yyyy format

    in the main startup prog. i have given this
    Code:
            Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-GB")
    this allows me to enter the date in dd/MM/yyyy format even where the system date is otherwise..
    but my prob is if someone types the date 01/04/2008 and is stored by me in the access using the following :

    Code:
    mCmd = "INSERT INTO RegApplication "
                mCmd = mCmd & " (AppDate)"
      mCmd = mCmd & " VALUES "
     mCmd = mCmd & " (@mAppDate)"
    cmd = New OleDbCommand(mCmd, MyConConnection)
    cmd.Parameters.AddWithValue("@mAppDate", OleDbType.Date).Value = Format(dtPkAppDate.Value, "dd/MM/yyyy")
    even then when the data is displayed it is shown as 04/01/2008..i.e. it takes 01 to b the month and 04 to b the date ...only at places where the system date is not as dd/MM/yyyy but if the system date is dd/MM/yyyy then the date is displayed correctly.

    pls. help me out..
    thankx

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] date issue

    You have no idea how many times I've posted this information. Dates are not stored in a database in any format. Dates are stored as binary data, NOT text. They are just a number. Format is only an issue when you DISPLAY a date value, for which you have to convert it to text. FORGET about format when it comes to storing dates. Just assign the binary Date value to your parameter and the date will be stored. Once you get the date back from the database and you want to display it to the user, THAT is when you need to worry about format.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [2008] date issue

    i am binding the data to the dtpicker and it is taking the value straight from the database ....and even then its showing it as 04/01/2008 rather than 01/04/2008

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] date issue

    Code:
            DateTimePicker1.Format = DateTimePickerFormat.Custom
            DateTimePicker1.CustomFormat = "dd/MM/yyyy"
    these can be set in the form designer.

    jmc told you that dates are always stored as a numeric value. how it is displayed is governed by the format.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [2008] date issue

    thankx dbasnett....but i have the format of the datetimepicker as custom which is dd/MM/yyyy

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] date issue

    Quote Originally Posted by kuldevbhasin
    i am binding the data to the dtpicker and it is taking the value straight from the database ....and even then its showing it as 04/01/2008 rather than 01/04/2008
    This is where you specify the format... You should worry about format only when you display it, as JMC have said. What type of control are you displaying the date?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [2008] date issue

    hi stanav.
    i am binding the date as follows
    Code:
    mCmd = "Select * From RegApplication ORDER BY Prd_Code & SerialNo"
    
            Dim da_RegApp As New OleDbDataAdapter(mCmd, MyConConnection)
            da_RegApp.Fill(ds_RegApp, "RegApplication")
            dTable = ds_RegApp.Tables(0)
    
    dtPkAppDate.DataBindings.Add(New Binding("Text", dTable, "AppDate"))
    how do i set the format here...?

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] date issue

    1. Set your DTP.Format to Custom and CustomFormat = "dd/MM/yyyy"
    2. Bind the "Value" property of the DTP instead of the "Text"
    Code:
    dtPkAppDate.DataBindings.Add("Value", dTable, "AppDate")
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  9. #9

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    493

    Re: [2008] date issue

    thankx stanav....let me try it out...thankx for helping me

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] date issue

    Another fine example of how explaining the situation clearly and fully allows a solution to be found. If we don't know the real problem then we can't solve it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] date issue

    well good morning JMC.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width