473,782 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime Problems

The date in my local machine is set to the dd/MM/yyyy format. When I
insert a date in a MS-Access DB table, it gets populated in the above
format. For e.g. if the date is, say, 8th March 2007, it gets
populated in the DB table as

08/03/2007

In other words, first the day is shown, then the month & finally the
year but when I retrieve it in ASP.NET & using DatePart, try to
extract the day & the month like this (assume that the date record
from the DB table is stored in a variable named dtOrderDate)

Response.Write( "Day: " & DatePart("d", dtOrderDate))
Response.Write( "Month: " & DatePart("m", dtOrderDate))

the first Response.Write outputs the day as 03 & the month as 08 where
as it should be the other way round i.e. the day should be 08 whereas
the month should be 03. The day & month values get reversed when I
just do Response.Write( dtOrderDate).

Can someone please point out what am I missing?

Mar 10 '07
24 2036
"Göran Andersson" <gu***@guffa.co mwrote in message
news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
>What date is 2007-08-03?

That is the third of august in the year 2007.
How do you know...?
Mar 11 '07 #11
On Mar 11, 9:31 am, "Mark Rae" <m...@markNOSPA Mrae.comwrote:
"Göran Andersson" <g...@guffa.com wrote in message

news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
What date is 2007-08-03?
That is the third of august in the year 2007.

How do you know...?
Göran is right. In my first answer I suggested to use ISO 8601 to be
sure which date is were inserted.

Mar 11 '07 #12
"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** ************@p1 0g2000cwp.googl egroups.com...
Göran is right. In my first answer I suggested to use ISO 8601 to be
sure which date is were inserted.
But that's the whole point - you can't be sure with this notation...

The fact that your code uses one particular format is neither here nor
there... The issue here is the word "inserted" i.e. typed in by a user...

Just because 2007-08-03 means 3rd August 2007 to you, doesn't imply that it
means the same to somebody else...

The only 100% guaranteed unambiguous method of date entry where users are
involved is to force three digit months and four digit years...
Mar 11 '07 #13
On Mar 11, 10:47 am, "Mark Rae" <m...@markNOSPA Mrae.comwrote:
"Alexey Smirnov" <alexey.smir... @gmail.comwrote in message

news:11******** ************@p1 0g2000cwp.googl egroups.com...
Göran is right. In my first answer I suggested to use ISO 8601 to be
sure which date is were inserted.

But that's the whole point - you can't be sure with this notation...

The fact that your code uses one particular format is neither here nor
there... The issue here is the word "inserted" i.e. typed in by a user...

Just because 2007-08-03 means 3rd August 2007 to you, doesn't imply that it
means the same to somebody else...

The only 100% guaranteed unambiguous method of date entry where users are
involved is to force three digit months and four digit years...

ISO 8601 is language independent
http://www.iso.org/iso/en/prods-serv...esandtime.html

Mar 11 '07 #14
"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** **************@ 8g2000cwh.googl egroups.com...
ISO 8601 is language independent
http://www.iso.org/iso/en/prods-serv...esandtime.html
Sigh...

OK, now watch...

You, the very clever developer, develop a very clever website where users
can register to receive a "Happy Birthday" email on their birthday.

You, the very clever developer, make sure that the textbox where the user
types in their date of birth uses the totally unambiguous industry-standard
ISO 8601 format.

I, the dumb user, come along and register on your site.

And I'm a *really* dumb user, so I don't pay attention to the writing beside
the textbox which tells me the date format that you, the very clever
developer, would like me to use - in fact, I'm such a dumb user that I don't
even understand what all that technical mumbo-jumbo means...

I, the dumb user, was born 12th March 1970.

However, I don't come from the same country as you - I come from a little
country that you, the very clever developer, have never even heard of...

So, I enter the following text:

1970-12-03

because that's how we format our dates in that little country that you, the
very clever developer, have never heard of...

I, the dumb user, hit the Save button.

You, the very clever developer, have written a superb validation routine
which examines the text that I, the dumb user, typed in. This validation
routine says "Yep, 1970-12-03 is a perfectly valid date" and permits my
registration to be saved to the database.

I, the dumb user, wonder why you, the very clever developer, are wishing me
a happy birthday in the first week of December...

*Now* do you get it...?
Mar 11 '07 #15
re:
Just because 2007-08-03 means 3rd August 2007 to you, doesn't imply that it means the same to
somebody else...
Indeed, using yyyy-mm-dd, it stands for March 8, 2007.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message news:ua******** *****@TK2MSFTNG P02.phx.gbl...
"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** ************@p1 0g2000cwp.googl egroups.com...
>Göran is right. In my first answer I suggested to use ISO 8601 to be
sure which date is were inserted.

But that's the whole point - you can't be sure with this notation...

The fact that your code uses one particular format is neither here nor there... The issue here is
the word "inserted" i.e. typed in by a user...

Just because 2007-08-03 means 3rd August 2007 to you, doesn't imply that it means the same to
somebody else...

The only 100% guaranteed unambiguous method of date entry where users are involved is to force
three digit months and four digit years...

Mar 11 '07 #16
On Mar 10, 5:29 pm, r...@rediffmail .com wrote:
.Parameters.Add WithValue("?", DateTime.Now.To String)
Maybe

..Parameters.Ad dWithValue("?", Format(DateTime .Now, "yyyy-MM-dd"))

will work?
Mar 11 '07 #17
On Mar 11, 12:09 pm, "Mark Rae" <m...@markNOSPA Mrae.comwrote:
"Alexey Smirnov" <alexey.smir... @gmail.comwrote in message

news:11******** **************@ 8g2000cwh.googl egroups.com...
ISO 8601 is language independent
http://www.iso.org/iso/en/prods-serv...esandtime.html

Sigh...

OK, now watch...

You, the very clever developer, develop a very clever website where users
can register to receive a "Happy Birthday" email on their birthday.

You, the very clever developer, make sure that the textbox where the user
types in their date of birth uses the totally unambiguous industry-standard
ISO 8601 format.

I, the dumb user, come along and register on your site.

And I'm a *really* dumb user, so I don't pay attention to the writing beside
the textbox which tells me the date format that you, the very clever
developer, would like me to use - in fact, I'm such a dumb user that I don't
even understand what all that technical mumbo-jumbo means...

I, the dumb user, was born 12th March 1970.

However, I don't come from the same country as you - I come from a little
country that you, the very clever developer, have never even heard of...

So, I enter the following text:

1970-12-03

because that's how we format our dates in that little country that you, the
very clever developer, have never heard of...

I, the dumb user, hit the Save button.

You, the very clever developer, have written a superb validation routine
which examines the text that I, the dumb user, typed in. This validation
routine says "Yep, 1970-12-03 is a perfectly valid date" and permits my
registration to be saved to the database.

I, the dumb user, wonder why you, the very clever developer, are wishing me
a happy birthday in the first week of December...

*Now* do you get it...?
As for the format in the international applications, using the textbox
to enter the date, is not a good idea at all. The very clever
developer will use a calendar control or a separated fields for day,
month and year, then the user is never entering a date by hand, and
you can control the format throughout the process.

Here's the problem in Access/OleDb and not in the validation design...

Mar 11 '07 #18
"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** **************@ 8g2000cwh.googl egroups.com...
As for the format in the international applications, using the textbox
to enter the date, is not a good idea at all. The very clever
developer will use a calendar control or a separated fields for day,
month and year, then the user is never entering a date by hand, and
you can control the format throughout the process.
Well obviously, but that's not what we're discussing here, is it...?
Mar 11 '07 #19
On Mar 11, 9:08 pm, "Mark Rae" <m...@markNOSPA Mrae.comwrote:
"Alexey Smirnov" <alexey.smir... @gmail.comwrote in message

news:11******** **************@ 8g2000cwh.googl egroups.com...
As for the format in the international applications, using the textbox
to enter the date, is not a good idea at all. The very clever
developer will use a calendar control or a separated fields for day,
month and year, then the user is never entering a date by hand, and
you can control the format throughout the process.

Well obviously, but that's not what we're discussing here, is it...?
Nope, here we have a totally different story.

Imagine, you have a Control Calendar on the page and you selected a
date, say, 8th March 2007.

Because your server is in UK you will get the string representation
Calendar.Select edDate.ToString as

08/03/2007 (dd/MM/yyyy)

Note, this has nothing to do with the manual insert, it's a local date
representation acc. to site/server settings.

Now, try to insert this string to MS Access using OleDb:

oledbCmd.Parame ters.AddWithVal ue("?", Calendar.Select edDate.ToString )

Because OleDb expected to have yyyy-MM-yy, or at least MM/dd/yyyy, it
will get the date as 3rd Aug 2007...

So, the problem is here not in the original date, but in the date
format used by OleDb and MS Access.

Mar 11 '07 #20

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

Similar topics

0
5162
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that accepts messages from .NET clients. The web method call includes an object as one of it's parameters - this reflected object has been given a property called "FutureDelivery" and expects a DateTime value. The clients may be in different timezones...
1
14976
by: Chris | last post by:
Hello, I'm having some problems right now with something that would seem to be rather simple (and probably is). But, the solution is escaping me right now. Currently, I have created a data structure with a timestamp in it. This is created in a DLL written in C++. The command that I use to get the timestamp is:
1
5079
by: Kevin | last post by:
Hi All I am having a problem retrieving a Date value from an Access 2000 database using the OLEDbProvider. Can someone tell me please how to create a DateTime Object with the date fro m the Database, I need the database date to subtract it from another date I have to gain the number of days that have elapsed. I just cannot seem to get this DateTime thing correct. The field in my Access Database is defined as a short date. This is kind...
38
807
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a FormatString, how can you convert the String back to a DateTime? DateTime.Parse(...) doesn't use the FormatString. Now admitedly, if the format string is just "MM", it can't be done. But if the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it...
11
7253
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why only that I have to listen to them because they know it better. They told also that in a business situation it is better to use datetime.parseexact for changing cultures and not to use the globalization setting. I did not give them this sample,...
1
2882
by: Ugur Ekinci | last post by:
Hi , I have two Sql Server 2000 on seperate machines , First one accepts datetime format like ("dd.MM.yyyy hh:mm:ss") And Second one accepts datetime format like ("MM.dd.yyyy hh:mm:ss") 1- Date formats are different because of SQL Collation? 2- Do regional Settings affect Sql date format? 3- (Important) When inserting a datetime into first server there is no problem (15.12.2000 12:12:12) , but when I insert into second server (if...
0
1443
by: H5N1 | last post by:
Hi there I know that a problem of different datetime strings formatting between asp.net and ms sql has been covered here widely, but what I couldn't find is the 100% safe way of getting datetime values from ms sql, processing them in asp.net and getting them back into sql without any risk with inconsistent Culture settings etc. My question is: wouldn't keeping the datetime variables all the time in datetime type, without any String...
5
2602
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field (MSSQL Server) it worked on my test machine. If I run the same application on another machine with different regional settings is not working. I tried with date_default_timezone_set to change timezone but is not changing. After...
5
3491
by: Michel Posseth [MCP] | last post by:
Hello we have encountered the following problems with the date time picker control A : datetime picker control gives focus to last entered field when moving back and forward with focus how do we reset this to the first field ? B : datetime picker in DD-MM-YYYY default format ( europe , NL-NL localization ) refuses an entry of 31 on the DD filed cause the month is already chosen to the current mont ( (02) februari wich only has 28...
10
1496
by: Jeff | last post by:
Hey ..NET 2.0 I'm about to create 2 input parameters for a method. These are 2 DateTime parameters - one named "from" and another named "to"... - from and to DateTime values... Okay the trick is that the "from" DateTime should be like this 01.<MM>.<YYYY ss:mm.hh which means that today is the 03.12.2007 then the
0
9641
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
10313
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
10146
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...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.