+ Reply to Thread
Results 1 to 12 of 12

Updating Date in Spreadsheet to table in SQL in UK date format

  1. #1
    Registered User
    Join Date
    09-29-2008
    Location
    england
    Posts
    40

    Updating Date in Spreadsheet to table in SQL in UK date format

    Hi, I have a couple of columns, once edited need to update a table in SQL. This is my code
    Please Login or Register  to view this content.
    However it is not taking UK date formats, it is assuming it is an american format, I get conversion of varchar data type to datetime results in an out-of-range value. What should I add to change the format? The format is in UK on the spreadsheet seemingly....

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    What do you mean not 'taking' UK dates?

    If you just take a date value from the cell there's good change it'll be in US format, even though is formatted as UK on the sheet.

    Try using Text instead of Value if you want to get the value as it's formatted.

    Even better as most databases kind of 'prefer' the ISO date format, yyyy-mm-dd, you could try formatting like that.

    Please Login or Register  to view this content.
    Might even be an idea to add a time part, eg 00:00:00.00.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-29-2008
    Location
    england
    Posts
    40

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    Hi,

    By not taking I mean if I enter 31/12/2014 into I2 it will error, but if I enter 12/31/2014 it will run the update query. I changed the target to text and also tried to set the format, but I still get the error when entering a UK date.

  4. #4
    Registered User
    Join Date
    09-29-2008
    Location
    england
    Posts
    40

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    Update, I changed all the dates via SQL to 31/12/2013. They appear on the spreadsheet as this date. However, once I change to 30/12/2013 I get the conversion of varchar data type, but if I enter 12/30/2013 it works fine.

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    To update/insert a date into a date field with SQL, the date must be between #s, not 's. ' is for string values., # is for dates.

    Dates can be a pain, I've always found it's safest to convert a date to it's decimal value (41000 odd) and insert that instead, can't get it wrong then.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    What database are you trying to update?

    Access? MySQL? MS SQL Server?

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    @Bellygas, that's only true for Access. SQL Server for example, stores datas as strings and must be passed in the format yyyy-mm-dd enclosed in single quotation marks

  8. #8
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    ahhhhh, didn't know that. Ta.

  9. #9
    Registered User
    Join Date
    09-29-2008
    Location
    england
    Posts
    40

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    I am updating MS SQL 2008_R2. It's frustrating as they look in the UK format on the sheet, but when I change the date to 01/11/2013 it goes into SQL as 2013/01/11, which is wrong. As the actual day of the month doesn't matter too much for me, I have resorted to entering 02/02/2013 or 11/11/2013 so when I spit out the data again at least the month is correct. I would prefer an actual solution though!

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    Did you try my suggestion of formatting the data in the ISO format and adding the time part?
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-29-2008
    Location
    england
    Posts
    40

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    I still get the same error :/

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Updating Date in Spreadsheet to table in SQL in UK date format

    What exactly did you try?

    Have you tested the SQL statement in SQL Server Management Studio?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Userform date entered in UK format but showing in US Format in spreadsheet
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-23-2013, 01:59 PM
  2. Date format on UserForm changes on Spreadsheet
    By darthelvis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2013, 05:41 PM
  3. [SOLVED] Macro to update pivot item (date format) in pivot table to latest date from data source.
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2012, 03:18 AM
  4. Excel 2007; pivot table not updating date format?
    By ncikusa in forum Excel General
    Replies: 0
    Last Post: 02-11-2012, 02:26 PM
  5. [SOLVED] Updating Pivot Table Column Date Data
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2005, 11:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1