473,748 Members | 10,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date in database

On my machine in the office I change the computer setting to English (UK) so
the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I make
the database stores it as 7/1/08 ?
Thank you.
Jan 8 '08 #1
30 5711

You can set the regional date format to anything you like, but when using SQLs to
insert or update data, you must use the yyyy-mm-dd format for SQL Server or the
mm/dd/yyyy format for Access.

If using the Addnew method then assigning the date value to the field, you must use
a date variable type:

dim strDate as string

strDate = date

open recordset "rs"

rs.addnew
rs!DateField = strDate
rs.update

The above wont work!!! (for any date format other than mm/dd/yyyy)

Change it to this:

dim dteDate as date

dteDate = date

open recordset "rs"

rs.addnew
rs!DateField = dteDate
rs.update

This example is so trivial, that you can assign Date directly, but when using
calculated dates the variable will most likely be needed.

To build an SQL with a date:

sSQL = "insert into MyTable (Mydate) values ("
sSQL = sSQL & "'" & format$(date, "yyyy-mm-dd") & "')"

For Access change that to:

sSQL = sSQL & "'" & format$(date, "mm/dd/yyyy") & "')"

HTH Saga
--

"fniles" <fn*******@SPAM MEpfmail.comwro te in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
On my machine in the office I change the computer setting to English (UK) so the date format is
dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is located on a machine that is
set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead
of 7/1/08. Why is it like that and how can I make the database stores it as 7/1/08 ?
Thank you.


Jan 8 '08 #2
Access will work fine with yyyy-mm-dd as well. However, you need to delimit
the dates with # characters in Access, not single quotes.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"Saga" <an******@somew here.comwrote in message
news:e2******** ******@TK2MSFTN GP04.phx.gbl...
This example is so trivial, that you can assign Date directly, but when
using
calculated dates the variable will most likely be needed.

To build an SQL with a date:

sSQL = "insert into MyTable (Mydate) values ("
sSQL = sSQL & "'" & format$(date, "yyyy-mm-dd") & "')"

For Access change that to:

sSQL = sSQL & "'" & format$(date, "mm/dd/yyyy") & "')"
"fniles" <fn*******@SPAM MEpfmail.comwro te in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>On my machine in the office I change the computer setting to English (UK)
so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I
make the database stores it as 7/1/08 ?
Thank you.

Jan 8 '08 #3
Thanks for catching that :-) I neglected to swap out the quotes for the # char.

Noted on the yyyy-mm-dd format for Access.

Saga
--
"Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .comwrote in message
news:OJ******** *****@TK2MSFTNG P06.phx.gbl...
Access will work fine with yyyy-mm-dd as well. However, you need to delimit the dates with #
characters in Access, not single quotes.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"Saga" <an******@somew here.comwrote in message news:e2******** ******@TK2MSFTN GP04.phx.gbl...
>This example is so trivial, that you can assign Date directly, but when using
calculated dates the variable will most likely be needed.

To build an SQL with a date:

sSQL = "insert into MyTable (Mydate) values ("
sSQL = sSQL & "'" & format$(date, "yyyy-mm-dd") & "')"

For Access change that to:

sSQL = sSQL & "'" & format$(date, "mm/dd/yyyy") & "')"
"fniles" <fn*******@SPAM MEpfmail.comwro te in message
news:%2******* *********@TK2MS FTNGP03.phx.gbl ...
>>On my machine in the office I change the computer setting to English (UK) so the date format is
dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is located on a machine that
is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead
of 7/1/08. Why is it like that and how can I make the database stores it as 7/1/08 ?
Thank you.


Jan 8 '08 #4

"fniles" <fn****@pfmail. comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
On my machine in the office I change the computer setting to English (UK)
so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I
make the database stores it as 7/1/08 ?
If the data type of the column is truly one of the various "date" data
types, the format of the date is irrelevant. Don't worry about it.

However, if the data type is actually text or characters, then you've got a
huge problem.
--
Mike
Microsoft MVP Visual Basic
Jan 8 '08 #5
Thank you everybody.
It turns out that in VB it works fine, but it does not work in ASP.
The data type of the column is truly a "date/time" column in Access
and "Datetime" column in SQL Server.

I do need the date to be stored in the correct format in the database,
because in my ASP program I do the following:
sDay = day(d)
sMonth = month(d)
sYear = year(d)
If it is not stored correctly in the database, the above functions do
not return the correct values.

It seems to work when I do the following (it stores 8/1/08 in the
database)
ssql = "update myTBL set colDate = format('8/1/08','dd/mm/yy') where
ID = 1"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.ActiveConnec tion = dbConnection
rs.open ssql

But when I do the following, it stores 1/8/08 in the database:
ssql = "select * from myTBL where ID = 1"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.ActiveConnec tion = dbConnection
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimisti c
rs.Source = sSql
rs.Open
rs("colDate") = cdate(#8/1/08#) '--got the same result when i do
rs("colDate") = cdate("8/1/08")
rs.Update
rs.close
set rs = nothing

I could use the "update" command on the 1st method, but I would like
to use the 2nd method if possible. Is it possible to make the 2nd
method above work ?
Thank you.
On Jan 8, 5:41*pm, "MikeD" <nob...@nowhere .eduwrote:
"fniles" <fni...@pfmail. comwrote in message

news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
On my machine in the office I change the computer setting to English (UK)
so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I
make the database stores it as 7/1/08 ?

If the data type of the column is truly one of the various "date" data
types, the format of the date is irrelevant. Don't worry about it.

However, if the data type is actually text or characters, then you've got a
huge problem.

--
Mike
Microsoft MVP Visual Basic
Jan 9 '08 #6
>>I do need the date to be stored in the correct format in the database,

The database has it's own way of storing dates - typically in a Julian
value.
How you want to display it is done via formating.

Take a look at this link:
http://www.sql-server-performance.co...tatype_p1.aspx

I myself work mainly with Oracle, which I think does something similar and
occasionally with Access.

Not sure about Access, but a google search could get you the details I'm
sure.
But what the Database engine itself is storing is irrelevant.
What's important is getting the data entered properly and displayed as
needed.

Steve Mussler

Jan 9 '08 #7

Inline

Saga

--
<fi************ *@SPAMMEgmail.c omwrote in message
news:45******** *************** ***********@v4g 2000hsf.googleg roups.com...
Thank you everybody.
It turns out that in VB it works fine, but it does not work in ASP.
The data type of the column is truly a "date/time" column in Access
and "Datetime" column in SQL Server.

I do need the date to be stored in the correct format in the database,
because in my ASP program I do the following:
sDay = day(d)
sMonth = month(d)
sYear = year(d)
If it is not stored correctly in the database, the above functions do
not return the correct values.

It seems to work when I do the following (it stores 8/1/08 in the
database)
ssql = "update myTBL set colDate = format('8/1/08','dd/mm/yy') where
ID = 1"

***Reply***
That format statement just does not look right. Use 4 digits for year
and yyyy-mm-dd format. Using dd/mm/yy will cause problems.
***

Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.ActiveConnec tion = dbConnection
rs.open ssql

But when I do the following, it stores 1/8/08 in the database:
ssql = "select * from myTBL where ID = 1"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.ActiveConnec tion = dbConnection
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimisti c
rs.Source = sSql
rs.Open
rs("colDate") = cdate(#8/1/08#)
'--got the same result when i do rs("colDate") = cdate("8/1/08")

***Reply***
When specifying a literal date (#8/1/08#) VB always expects mm/dd/yyyy
format. So the above will be interpreted as Aug 1st, 2008. The CDate(##)
statement above is useless since you are in effect converting a date into
a date.

On the other hand, cdate("8/1/08") is converting the string "8/1/08"into a
date which is a step in the right direction, but it is still not 100% "safe":

"CDate recognizes date formats according to the locale setting of your
system." - MSDN Library

I did the following in the immediate window:

? cdate("8/1/08")
08/01/2008 (2nd) 8th of Jan
8/1/2008 (1st) Aug 1st

I set my regional settings to English US for the 1st try. I then set the
regional settings to English UK for the 2nd test. Note how the "same" date
was displayed, but is intepreted differently depending on locale. Best to stay
away from having dates in strings and using these to update tables or do
further date calculations where the month and day could be ambiguous.

I did another test (in the immediate wndow):

? #8/1/2008#
8/1/2008 US setting Aug 1st 2008
01/08/2008 UK setting 1st of Aug 2008 Same date!!!

Note how the above literal is interpreted as the same date but when displayed
it is done using the correct locale format. As mentioned before, when the #
char is used to specify a date literal it is always interpreted as mm/dd/yyyy.
***

rs.Update
rs.close
set rs = nothing

I could use the "update" command on the 1st method, but I would like
to use the 2nd method if possible. Is it possible to make the 2nd
method above work ?
Thank you.
***PS: I have no idea why the OP's text was not indented with the ">"
char. It seems to have been only for this message.

On Jan 8, 5:41 pm, "MikeD" <nob...@nowhere .eduwrote:
"fniles" <fni...@pfmail. comwrote in message

news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
On my machine in the office I change the computer setting to English (UK)
so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I
make the database stores it as 7/1/08 ?

If the data type of the column is truly one of the various "date" data
types, the format of the date is irrelevant. Don't worry about it.

However, if the data type is actually text or characters, then you've got a
huge problem.

--
Mike
Microsoft MVP Visual Basic

Jan 9 '08 #8
fniles wrote:
On my machine in the office I change the computer setting to English (UK) so
the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I make
the database stores it as 7/1/08 ?
Thank you.
Would setting the locale help?
Not sure if your using VBScript, but here is something about it:
http://www.w3schools.com/vbscript/func_setlocale.asp

Steve
Jan 9 '08 #9
Although setting the locale via VB6 code -could- be a potential "fix", I humbly
advice against it as it might make more enemies than friends. One's app
should adapt the locale setting, NOT the locale setting to the app.

Saga
--

"Dooza" <st*****@SPAM.d ooza.tvwrote in message news:O8******** *****@TK2MSFTNG P04.phx.gbl...
fniles wrote:
>On my machine in the office I change the computer setting to English (UK) so the date format is
dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is located on a machine that
is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead
of 7/1/08. Why is it like that and how can I make the database stores it as 7/1/08 ?
Thank you.

Would setting the locale help?
Not sure if your using VBScript, but here is something about it:
http://www.w3schools.com/vbscript/func_setlocale.asp

Steve

Jan 9 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
9299
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted to the MYSQL date field. The type of field is INT (11) so that I can instead of the standard...
5
7105
by: Adrian Parker | last post by:
Hi. I have a date time picker in my program which uses ADO to read from an Access database. It works perfectly, unless the database is empty (no records) when opened. When you try to open an empty database, the date time picker returns error 545. Any attempts to progmatically add new records after the empty database has been opened returns, or to use the DTP and set a new date for those added records, "Field not updateable, Bound...
15
43012
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our code has worked satisfactorily with many databases, including many instances MS SQLServer 2000...
3
1426
by: C White | last post by:
got another one for you guys out there, and thanks again for the help with my "counting question" this time i'm looking to select records based on date, the database stores the date as mm/dd/yyyy time am/pm ie: 08/11/2004 2:42:28 PM and unfortunately the field is called date this much I know if i want to select based on date: select from table where =
8
558
by: the other john | last post by:
I have a client that wants a time field to resolve to 7:00 PM rather than 7:00:00 PM (wants the seconds gone). vbLongTime provides the later but vbShortTime produces a 24 hour version or 19:00. Any suggestions? Thanks!
2
6970
by: Tatiana Zadiraka | last post by:
I use DB2 8.1 with FixPack 5. In command line for sql I get all DATE columns only in MM-DD-YYYY format. Of course, DATE('20-12-2003') gives me an error SQL0181N The string representation of a datetime value is out of range. SQLSTATE=22007 My db config is: Database territory = RU
8
3655
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as text fields. Each date for example 10/31/03 or October 31st 2003 is stored as 10/31/A3 in the system. My reasoning for this is because they couldn't solve their Y2K problem or this is their solution to it. All dates prior to 2000 are stored...
1
3025
by: JonathanParker | last post by:
Another quick one! Trying to search for records by both accounting period and by year in two seperate queries actioned by option buttons. I've sorted the formatting so it's in a UK format but I keep getting the same error '(3122) you tried to execute a query that does not include the specific expression 'tblAccounting.Period=0406 And tblProduction.DepartmentID=1 ?And tblUtility.UtilityID=1' as part of an aggregate function.' I can't...
3
3541
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 sorting out a few glitches though. Since i upgraded from ms access database to MySQL, i have added about 4 articles to test the new setup. I note some fields aren't being added in the new mySql database for the new 4 records. When i ran the MySQK...
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.