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. VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400

VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400

Scheduled Pinned Locked Moved Visual Basic
csharpcssdatabasehelp
19 Posts 5 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.
  • U User 11833437

    It is actually saving it to the table in these formats. How can I get the app to save it in the correct format in the access table? Also, what causes the ..946341400?

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    No, it is saving it as a Date/DateTime value as shown in your code. As I said, the format only applies when you display it.

    1 Reply Last reply
    0
    • U User 11833437

      Thanks for the answer. I figured it out once I stopped over thinking it. dtPick5.Value.ToString("MM/dd/yyyy" did the trick for both issues.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      You should never store dates as strings, use Date or DateTime values, and only apply formatting when it is displayed. For example the date 01/02/03 could be 1st February 2003, 2nd January 2003, or even 3rd February 2001, depending on where you live.

      U 1 Reply Last reply
      0
      • L Lost User

        You should never store dates as strings, use Date or DateTime values, and only apply formatting when it is displayed. For example the date 01/02/03 could be 1st February 2003, 2nd January 2003, or even 3rd February 2001, depending on where you live.

        U Offline
        U Offline
        User 11833437
        wrote on last edited by
        #7

        If dtPick5.Value.ToString("MM/dd/yyyy" isn't the correct way then can you post an example of how to properly do it?

        L 1 Reply Last reply
        0
        • U User 11833437

          If dtPick5.Value.ToString("MM/dd/yyyy" isn't the correct way then can you post an example of how to properly do it?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #8

          At the risk of repeating myself again and again: use the Value. That way the date can be formatted for display into any culture.

          U 1 Reply Last reply
          0
          • L Lost User

            At the risk of repeating myself again and again: use the Value. That way the date can be formatted for display into any culture.

            U Offline
            U Offline
            User 11833437
            wrote on last edited by
            #9

            Heaven forbid you repeat yourself or provide a code example.... dickhead. It may be wrong but it works the way I want so until I see an example I am going to keep it this way and move on. I will worry about figuring out what exactly you are talking about later.

            L P 3 Replies Last reply
            0
            • U User 11833437

              Heaven forbid you repeat yourself or provide a code example.... dickhead. It may be wrong but it works the way I want so until I see an example I am going to keep it this way and move on. I will worry about figuring out what exactly you are talking about later.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              Member 11866893 wrote:

              Heaven forbid you repeat yourself or provide a code example....

              The explanation is spot on, but to expand with code;

              dim someDateString as String = dtPick5.Value.ToString(..

              This creates a text, with the date formatted in some culture.

              dim someDate as DateTime = dtPick5.Value

              Here the value is taken as is, without formatting. It is stored as a decimal value, with "days" in the integer part from a given offset, and the decimal part representing time. It is a format-independant version, and that's how it should be stored. Internally, your application should use DateTime values, and only formatting them as strings when displaying. Saving the value in DateTime type is important; if you use a localized and formatted version tht is actually a string, the computer will have to convert that to a real DateTime for each operation.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              1 Reply Last reply
              0
              • U User 11833437

                Heaven forbid you repeat yourself or provide a code example.... dickhead. It may be wrong but it works the way I want so until I see an example I am going to keep it this way and move on. I will worry about figuring out what exactly you are talking about later.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #11

                Ah yes, the lazy person's fallback position when you don't get someone else to do your work: abuse.

                L 1 Reply Last reply
                0
                • U User 11833437

                  Heaven forbid you repeat yourself or provide a code example.... dickhead. It may be wrong but it works the way I want so until I see an example I am going to keep it this way and move on. I will worry about figuring out what exactly you are talking about later.

                  P Offline
                  P Offline
                  phil o
                  wrote on last edited by
                  #12

                  You decently cannot insult those who try to help.

                  "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                  1 Reply Last reply
                  0
                  • U User 11833437

                    When I save the attendance date from a datetimepicker as a date prior to today's date it records acceptable format but not what I really want. When I select today's date it records a date like this 2020-02-25 08:28:00.946341400. The secondary issue is what I eluded to above. I set the custom format in the form_load to "MM, dd, yyyy" and when I select a date prior to today's date it records the date like this 2020-01-29 08:34:25. Here is the Save Button code

                    Dim inserted As Integer = 0
                    For Each row As DataGridViewRow In dgvAttend.Rows
                    Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("chkbox").Value)
                    If isSelected Then
                    Access.AddParam("@DTE", dtPick5.Value)
                    Access.AddParam("@SID", row.Cells("StudentID").Value)
                    Access.AddParam("@LN", row.Cells("LastName").Value)
                    Access.AddParam("@FN", row.Cells("FirstName").Value)

                                Access.ExecQuery("INSERT INTO Attend (TrainDate,StudentID,LastName,FirstName) " &
                                         "VALUES (@DTE,@SID,@LN,@FN); ")
                    
                                inserted = inserted + 1
                            End If
                        Next
                    
                        If inserted > 0 Then
                            MessageBox.Show(String.Format("{0} records inserted.", inserted), "ACJTracker", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        End If
                    

                    Here is the form load

                    dtPick5.Format = DateTimePickerFormat.Custom
                    dtPick5.CustomFormat = "MM, dd, yyyy"
                    RefreshAttendGrid()

                    Here is the refresh Grid

                    dtPick5.Format = DateTimePickerFormat.Custom
                    dtPick5.CustomFormat = "MM, dd, yyyy"

                        ' RUN QUERY
                        Access.ExecQuery("SELECT StudentData.StudentID, StudentData.LastName, StudentData.FirstName FROM StudentData ORDER BY StudentID ASC")
                    
                        ' REPORT & ABORT ON ERRORS
                        If NoErrors(True) = False Then Exit Sub
                    
                        dgvAttend.DataSource = Access.DBDT
                    

                    Does anyone know how I correct these issues?

                    P Offline
                    P Offline
                    phil o
                    wrote on last edited by
                    #13

                    Weird since examples seem to work with a single comma. You could try to escape extra characters (i.e., commas):

                    dtPick5.CustomFormat = "MM',' dd',' yyyy"

                    or keep using a more common form.

                    "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                    1 Reply Last reply
                    0
                    • L Lost User

                      Ah yes, the lazy person's fallback position when you don't get someone else to do your work: abuse.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #14

                      It's the VB forum; it looks like a frustrated coder. Don't take it as a personal insult.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      L 1 Reply Last reply
                      0
                      • L Lost User

                        It's the VB forum; it looks like a frustrated coder. Don't take it as a personal insult.

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #15

                        Eddy Vluggen wrote:

                        Don't take it as a personal insult.

                        I don't; my shoulders are broad enough. But I do take exception to people being abusive on this site.

                        L Z 2 Replies Last reply
                        0
                        • U User 11833437

                          When I save the attendance date from a datetimepicker as a date prior to today's date it records acceptable format but not what I really want. When I select today's date it records a date like this 2020-02-25 08:28:00.946341400. The secondary issue is what I eluded to above. I set the custom format in the form_load to "MM, dd, yyyy" and when I select a date prior to today's date it records the date like this 2020-01-29 08:34:25. Here is the Save Button code

                          Dim inserted As Integer = 0
                          For Each row As DataGridViewRow In dgvAttend.Rows
                          Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("chkbox").Value)
                          If isSelected Then
                          Access.AddParam("@DTE", dtPick5.Value)
                          Access.AddParam("@SID", row.Cells("StudentID").Value)
                          Access.AddParam("@LN", row.Cells("LastName").Value)
                          Access.AddParam("@FN", row.Cells("FirstName").Value)

                                      Access.ExecQuery("INSERT INTO Attend (TrainDate,StudentID,LastName,FirstName) " &
                                               "VALUES (@DTE,@SID,@LN,@FN); ")
                          
                                      inserted = inserted + 1
                                  End If
                              Next
                          
                              If inserted > 0 Then
                                  MessageBox.Show(String.Format("{0} records inserted.", inserted), "ACJTracker", MessageBoxButtons.OK, MessageBoxIcon.Information)
                              End If
                          

                          Here is the form load

                          dtPick5.Format = DateTimePickerFormat.Custom
                          dtPick5.CustomFormat = "MM, dd, yyyy"
                          RefreshAttendGrid()

                          Here is the refresh Grid

                          dtPick5.Format = DateTimePickerFormat.Custom
                          dtPick5.CustomFormat = "MM, dd, yyyy"

                              ' RUN QUERY
                              Access.ExecQuery("SELECT StudentData.StudentID, StudentData.LastName, StudentData.FirstName FROM StudentData ORDER BY StudentID ASC")
                          
                              ' REPORT & ABORT ON ERRORS
                              If NoErrors(True) = False Then Exit Sub
                          
                              dgvAttend.DataSource = Access.DBDT
                          

                          Does anyone know how I correct these issues?

                          M Offline
                          M Offline
                          Mycroft Holmes
                          wrote on last edited by
                          #16

                          I think the issue you may be facing is that you are storing the data as datetime which naturally includes the time component. If you do not need the time component then you should store it as a date data type (not sure if Access has such a data type). If the is a requirement for the time component then you need to format every instance of the data as it is presented and you need to cater for the time component in all your queries ie you can no longer query for a date you will need to query for the range of datetime records between midnight and midnight the date after.

                          Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                          1 Reply Last reply
                          0
                          • L Lost User

                            Eddy Vluggen wrote:

                            Don't take it as a personal insult.

                            I don't; my shoulders are broad enough. But I do take exception to people being abusive on this site.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #17

                            Richard MacCutchan wrote:

                            But I do take exception to people being abusive on this site.

                            Good for me I never did that :rolleyes: It is one of umpteen coders frustrated at how dates don't work like they imagine. Not something unique nor new.

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                            L 1 Reply Last reply
                            0
                            • L Lost User

                              Richard MacCutchan wrote:

                              But I do take exception to people being abusive on this site.

                              Good for me I never did that :rolleyes: It is one of umpteen coders frustrated at how dates don't work like they imagine. Not something unique nor new.

                              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #18

                              The trouble with some of these people is that they will not accept advice. So no matter how much you try to help them they insist on doing it their way, without understanding the potential problems that can come back to bite them.

                              1 Reply Last reply
                              0
                              • L Lost User

                                Eddy Vluggen wrote:

                                Don't take it as a personal insult.

                                I don't; my shoulders are broad enough. But I do take exception to people being abusive on this site.

                                Z Offline
                                Z Offline
                                ZurdoDev
                                wrote on last edited by
                                #19

                                Richard MacCutchan wrote:

                                But I do take exception to people being abusive on this site.

                                Why is that, Thou sodden-witted lord?

                                Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                                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