Date Format changes when inserting into table if start date and end date cross one or more months

user3299185

I have an Access 2013 form which has two unbound date fields, FromDate and ToDate. I insert these into a table (TblGuestBooking) which has an autonumber key field, so this doesn't feature in the SQL statement to follow.

If the FromDate and ToDate are in the same month, the dates are entered as dd/mm/yy, the format of the form field. If, however, the From date is in one month and the to date is in the next month or later month, the format changes to mm/dd/yy for the subsequent months.

for example 26/2/14 to 3/3/14 results in the following table entries:

26/02/14,
27/02/14,
28/02/14,
03/01/14,
03/02/14,
03/03/14

This is the code snippet I am using to put the dates into the table (BookingID is obtained from the form.)

Dim BookingDate As Date

Dim SQLString As String

....

BookingDate = FromDate

Do
    SQLString = "INSERT INTO TblGuestBooking ([BookingDate], [BookingID])  VALUES (#" & BookingDate & "#" & "," & Me.GuestSuiteBookingID & ")"

    DoCmd.SetWarnings False
    DoCmd.RunSQL SQLString
    DoCmd.SetWarnings True
    BookingDate = BookingDate + 1
Loop Until BookingDate = ToDate + 1

If you've read this far, thank you for your time. If you can help me out, many, many thanks.

Gord Thompson

When processing date literals (text values enclosed by "hash marks" #) Access SQL will always interpret ambiguous xx-yy-zzzz dates as mm-dd-yyyy, regardless of the regional setting in place on the computer. So, if your machine is configured to display short dates as dd-mm-yyyy and you create an Access query that uses #04-02-2014# it will always be interpreted as April 2, not February 4.

The solution is to always format date literals as unambiguous yyyy-mm-dd values. In your case, instead of

... VALUES (#" & BookingDate & "#" ...

you would use something like

... VALUES (#" & Format(BookingDate, "yyyy-mm-dd") & "#" ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

time format for Start date, End date - SSRS

From Dev

TSQL generate months based on start and end date

From Dev

To get start date and end date of months between the given dates range

From Dev

Need to get the minimum start date and maximum end date, when there is no break in months

From Dev

Start Date and End Date in Bootstrap

From Dev

Start Date and End Date in AngularJS

From Dev

Extract months from start and end date in VBA - Excel

From Dev

Extract months from start and end date in VBA - Excel

From Dev

Howto grep over months with defined start and end date

From Dev

PHP: Inserting date into a table

From Dev

Date difference between end date to start date

From Dev

one cell for each date between start and end date

From Dev

date time format adds one more hour

From Dev

how to get start date and end date of sequence days in table?

From Dev

Combine start date and end date from 2 tables into single table

From Dev

Splitting YYYYMMDD format date into months?

From Dev

How to add months to a date of this format?

From Dev

Aggregate with a start and end of date

From Dev

how can i run the loop from start date to end date for every 3 months in php

From Dev

MS Access: Group by months for each month between Start Date and End Date

From Dev

how can i run the loop from start date to end date for every 3 months in php

From Dev

Inserting date in Mysql (codename one)

From Dev

Inserting a date into a table using PDO

From Dev

Start and end date from date range

From Dev

Start Date and End Date Of current month in MySql?

From Dev

Angularjs start date and end date validations

From Dev

JQuery - end date less than start date

From Dev

Qml Calendar - selecting Start Date and End Date

From Dev

Qml Calendar - selecting Start Date and End Date

Related Related

  1. 1

    time format for Start date, End date - SSRS

  2. 2

    TSQL generate months based on start and end date

  3. 3

    To get start date and end date of months between the given dates range

  4. 4

    Need to get the minimum start date and maximum end date, when there is no break in months

  5. 5

    Start Date and End Date in Bootstrap

  6. 6

    Start Date and End Date in AngularJS

  7. 7

    Extract months from start and end date in VBA - Excel

  8. 8

    Extract months from start and end date in VBA - Excel

  9. 9

    Howto grep over months with defined start and end date

  10. 10

    PHP: Inserting date into a table

  11. 11

    Date difference between end date to start date

  12. 12

    one cell for each date between start and end date

  13. 13

    date time format adds one more hour

  14. 14

    how to get start date and end date of sequence days in table?

  15. 15

    Combine start date and end date from 2 tables into single table

  16. 16

    Splitting YYYYMMDD format date into months?

  17. 17

    How to add months to a date of this format?

  18. 18

    Aggregate with a start and end of date

  19. 19

    how can i run the loop from start date to end date for every 3 months in php

  20. 20

    MS Access: Group by months for each month between Start Date and End Date

  21. 21

    how can i run the loop from start date to end date for every 3 months in php

  22. 22

    Inserting date in Mysql (codename one)

  23. 23

    Inserting a date into a table using PDO

  24. 24

    Start and end date from date range

  25. 25

    Start Date and End Date Of current month in MySql?

  26. 26

    Angularjs start date and end date validations

  27. 27

    JQuery - end date less than start date

  28. 28

    Qml Calendar - selecting Start Date and End Date

  29. 29

    Qml Calendar - selecting Start Date and End Date

HotTag

Archive