Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL date problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL date problem

 Post Reply Post Reply Page  12>
Author
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Topic: SQL date problem
    Posted: 07 April 2008 at 2:30pm
Hi,

i am having trouble copying dates into my live sql db, i've tried all sorts of combinations of mm/dd/yyyy, yyyy/mm/dd etc but every time i run my script to copy from a temp db and paste into my live db i get the following error message:

[Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

the records with a date of 01/12/2008 paste in with no problems, but it fails at the date of 19/02/2008
now i assumed this was because there isn't a 19th month so i swapped the format around to dd/mm/yyyy and it still failed at the very same record

this is really frustrating at the moment, any help would be appreciated.

thanks
Mark
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 07 April 2008 at 2:33pm
You could use the ISO international date format eg:-

2008-02-19

However, if you use SQL Server 2000 or below you need to remove the '-' eg:-

20080219

This format is used in Web Wiz Forums as find it works with all locales, at least not heard of anyone having any date issues since moving across to this format some years ago.
Back to Top
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Posted: 07 April 2008 at 2:39pm

my temp db is an access db and its here where i state my date format, even if access has the yyyy/mm/dd format it still fails when copying to the sql db

when you say 20080219 you mean with no / in between?
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 07 April 2008 at 2:51pm
The ISO format which is recognised by all databases uses dashes '-' not slashes '/'

It's only SQL Server 2000 which likes it without the dashes.

Whether you can set this format in Access is another matter though, as internally Access stores dates as a double integer number from 1899 or some date like that eg.:-

6346363.98798
Back to Top
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Posted: 07 April 2008 at 2:58pm
i can set the date within access to yyyymmdd and it displays as exactly that but when clicking on it, the value changes to the dd/mm/yyyy format then clicking away changes it back to yyyymmdd which looks correct

i've just tried this format and it still fails on the same record,
it is Microsoft SQL Server 2000 - 8.00.2187 (Intel X86) that im using so i think i have the correct format without the '-' like you said




Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 09 April 2008 at 2:54pm
Look at the cast or convert function when importing dates into sql if they come from access (depending on how you do it) they maybe flagged as varchar(x) and sql will reject that even if the format is write. If you do e.g. insert into sqltable Values(Convert(datevalue as datetime)) it should work.
Again, it really depends how you transfer your data

Back to Top
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Posted: 13 April 2008 at 11:21am
great

i've managed to stop the script failing using convert datevalue but all my dates are now 01/01/1900  ???
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 14 April 2008 at 2:11pm
what was the original date formatted like? You need to make sure they are based on the same calendar/date format
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.