473,385 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Date problem: suddenly transposing day and month a la USA on one form

Something very mad is happening. On a form there is a text box into which a date (in format dd/mm/yy) is entered (the default being today's date). When the record is saved, it goes into the table as mm/dd/yy. So, for example, if the date entered is 10/04/10 (10th April 2010) it goes in as 04/10/10 (4th October), and comes out as that whenever it's retrieved thereafter.

There are lots of places in the db where dates are entered and saved, and this problem occurs nowhere except on this one form. There's no code behind the date field, and nothing odd about the table: format for both is just set to Short Date.

I have checked the Windows Regional Settings, and date/time is set to UK ... anyway, that setting should apply everywhere (if US then US everywhere, if UK then UK everywhere).

I've been ferreting about for the source of this problem for HOURS!!! Help! Has anyone else experienced this 'madness'? If so, what can be done to stop it?
Apr 10 '10 #1

✓ answered by missinglinq

Allen Browne, who lives in a British Commonwealth nation (do they still call it that?) has an excellent treatise on the subject, that may help:

http://www.allenbrowne.com/ser-36.html

Linq ;0)>

10 4328
missinglinq
3,532 Expert 2GB
Allen Browne, who lives in a British Commonwealth nation (do they still call it that?) has an excellent treatise on the subject, that may help:

http://www.allenbrowne.com/ser-36.html

Linq ;0)>
Apr 10 '10 #2
Brilliant article, which I have book-marked. I now know exactly what the problem is (i.e. it's because I'm using a temporary table filled in code) but I haven't solved it, because his function SQLDate returns a string, which is the wrong data type for the table into which it is being saved. Can't change that field in the table into a string because then it won't sort properly by date.

Anyway, now I know where the problem is I can start to figure out a different solution, avoiding the temporary table.
Apr 10 '10 #3
missinglinq
3,532 Expert 2GB
Glad it helped! Allen is known in some quarters as the "Wonder from Down Under!" A number of his papers have actually been co-opted by Microsoft's Knowledge Base for Access.

Good luck in finding a workaround!

Linq ;0)>
Apr 10 '10 #4
Oh dear! Several hours later I've failed to work around the problem, as the alternative query is insanely complicated and I can't get it to work. So, I reverted to the original code form.

The code includes the following SQL and then runs it

Expand|Select|Wrap|Line Numbers
  1.          sqlStr = "INSERT INTO TEMP_FOR_ALL_GOOD_DEEDS " _
  2.                     & "(DeedID, EventID,ContactID, " _
  3.                     & "DeedType, EventTitle, StItemTitle, MoneyValue, GiftAid, " _
  4.                     & "CorporateOrPersonal, DateOfDeed,Notes) " _
  5.                 & "VALUES (" & DiD & "," & EvID & ", " & ContID & ",'" & DType _
  6.                 & "','" & EvTitle & "','" & StItemTitle & "'," & moneyVal & "," & _
  7.                      rstDeeds!GiftAid & ", '" & rstDeeds!CorporateOrPersonal & _
  8.                      "',#" & rstDeeds!DateOfDeed & "#, '" & rstDeeds!Notes & "') "
  9.          DoCmd.RunSql
  10.  
It works (or did before I messed about here trying to get shorter lines for you) except that, as per my original Q,
#" & rstDeeds!DateOfDeed & "#
gets stored as mm/dd/yy instead of dd/mm/yy. Thanks to the article you pointed me at, I now know why this is happening, but I still don't know how to cure it. If I make the date into a string using Alan's function, and change the field in the temporary table to a string (Text) I can get the date in there 'the right way round' as a string, but that's no good because I want to order the table by these dates.

Is there any way of telling the INSERT statement how to format the date? I'm pretty stuck!!!
Apr 10 '10 #5
The solution is only slightly less bizarre than the problem!

If instead of running an sql statement to get the records into the temporary table you do it using a recordset for the temp table and putting the records in one by one using 'rst.AddItem' the problem doesn't happen. Dates go in just fine.

I hope that may help someone else out, as I feel a bit selfishly 'me,me,me' about my use of this site - nice to contribute something useful at last!
Apr 10 '10 #6
NeoPa
32,556 Expert Mod 16PB
It may be related to the fact that literal dates in SQL are formatted as m/d/y entirely regardless of the regional settings. This would not have any effect on Recordset processing within your code, but if you created a SQL string in your code that set up date literals (using # chars) and didn't take this into consideration, then you could certainly expect this problem. Being as you're from Britain, you're more likely to fall foul of this than someone from the States. Many of our American experts (and some without even that excuse) still overlook this issue when giving advice about date usage. Check out Literal DateTimes and Their Delimiters (#) for more on this subject.

PS. posted code on the internet often suffers from this issue because it works whenever tested in the USA. This is certainly true of the code you posted in your post #5. It will not work correctly in Britain.
Apr 13 '10 #7
Yes, that's just how it is with literal dates! It's annoying, because it seems much neater on many occasions to 'run' some SQL direct rather thand opening a recordset and being all 'procedural' about it.
Apr 14 '10 #8
NeoPa
32,556 Expert Mod 16PB
It's still perfectly possible to do. All you need to do is to format (use Format() for this) the date in SQL date format (m/d/yyyy). It's explained with examples in the linked article.
Apr 14 '10 #9
Thank you. sorry about the delay in saying 'thanks' ... I've been away looking after daughter's puppies!!!
Apr 24 '10 #10
NeoPa
32,556 Expert Mod 16PB
You're most welcome :)

We don't panic too much about delays on here. There are always going to be issues interfering with access. We're just happy you got your issue resolved and understood.
Apr 26 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Piotr Pietrowski | last post by:
Hello everybody, I have a *big* problem. I thought its not that big problem for you professionals... Anyway, I have a begin date which has 3 dropdown boxes (day/Month/Year). The same for the...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
by: simina | last post by:
Hi... I have an "appointments" page where the user should (or not necessarily) choose a date and time for his appointment, from 6 combo boxes:year, month, day, hour, minute and AM or PM, without...
5
by: Astra | last post by:
Hi All I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004 .... 2020), do you know of any js validation check I can use to check whether these values are older than...
16
by: KL | last post by:
I am working on a problem and desperately need help! I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables...
6
by: BlackFireNova | last post by:
Using Access 2002 I am writing a report which draws data from several different tables. I can't link all the tables in a query, as some can not be related without truncating the data. I plan...
2
by: Danny | last post by:
Hi I'm using asp.net , visual studio.NET 2003 , c#. I have a problem that occurred only on my computer And not on other developer's computers. My CultureInfo.CurrentCulture is "he-IL" But when...
3
by: Bob Sanderson | last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates into the date fields using a JavaScript calendar, similar to the way phpMyAdmin does. Can anyone recommend a JavaScript...
7
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.