Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Database dates getting mixed up?
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

Sirius
Starting Member

45 Posts

Posted - 12 March 2002 :  17:09:43  Show Profile
I'm using ASP and Access 2000

In my SQL string I'll be storing a date in a date field in my DB such as "3/12/2002 4:00:27 PM". This stores it, but then when I look at the DB directly in Access or retrieve the date I've just stored it comes out as "12/3/2002 4:00:27 PM". The month and date have been interchanged. Obviously this is screwing up my DateDiff checks. There is probably a simple solution to this. Will someone help a noob out and point me in the right direction? Thanks in advance!




Edited by - Sirius on 12 March 2002 17:11:01

Bunce
New Member

Australia
84 Posts

Posted - 12 March 2002 :  18:26:04  Show Profile  Send Bunce an ICQ Message
Store your dates in the format "yyyy/mm/dd time" so that there can be no discrepencies.

Then use the inbuilt date functions of ASP to format the date as you wish for output.

Cheers,

Andrew

======================================================
There have been many, many forum posts made throughout the world...
This was one of them!
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 12 March 2002 :  19:05:18  Show Profile  Send ruirib a Yahoo! Message
I think the internal Access format is connected to your regional settings. At least I can store date values in Access and see them in the proper format.
I would recommend that you use the VbScript date funtions to get the date out in a proper format.

I can show you some sample code to do it if you need it.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Bunce
New Member

Australia
84 Posts

Posted - 13 March 2002 :  02:45:16  Show Profile  Send Bunce an ICQ Message
It shouldn't matter how the storage of a date 'looks' in a database.

IMO, we should try to ALWAYS use ISO format ("YYYY/MM/DD"), and build an output function in the scripting language of your choice that you can reuse when required.

It saves future troubles in terms of porting to other databases, function use, regional differences etc.

http://www.adopenstatic.com/faq/DateswithAccess.asp
http://www.4guysfromrolla.com/webtech/011701-1.shtml

Cheers,

Andrew



======================================================
There have been many, many forum posts made throughout the world...
This was one of them!

Edited by - Bunce on 13 March 2002 03:19:38
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 13 March 2002 :  07:56:30  Show Profile  Send ruirib a Yahoo! Message
Hi,

I agree with you that it's always better to have a standard way of dealing with dates, specially if you need to make portable code. But you need to use extra code for it to work, just as the very interesting examples in the links you provided show.

I do it differently from the examples in the code. I just get each part of the date to write to the DB and use it in the DateSerial VbScript function and store the returned value in Access. It's just simpler than the examples provided.

DateSerial takes (year,month,day) as parameters, so there is no way to make mistakes. If you know the date components (year, month,date) you can write them directly in DateSerial. If you don't it's pretty easy to separate them using InStr.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Bunce
New Member

Australia
84 Posts

Posted - 13 March 2002 :  17:50:03  Show Profile  Send Bunce an ICQ Message
Yep, good points.

Guess it's a habitual thing I've got used to :=)

It's just amazing how many questions arise in newsgroups as to why date formatting / conversions don't work and most can usually be solved by storing and manipulating them this way.

Cheers,

Andrew



======================================================
There have been many, many forum posts made throughout the world...
This was one of them!
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 13 March 2002 :  18:05:21  Show Profile  Send ruirib a Yahoo! Message
quote:

Guess it's a habitual thing I've got used to :=)


That happens frequently when you develop. You spend your time doing it once and then you just reuse the solution. This makes sense.
Sometimes it takes an outside view to "alert" you to alternative ways of doing things. That's why I value other people's views on things. Quite often they prompt you to review your own view of the matter and get a better solution (I'm not saying this is the case here, just describing what often happens with me...)

quote:

It's just amazing how many questions arise in newsgroups as to why date formatting / conversions don't work and most can usually be solved by storing and manipulating them this way.



You know most people don't even realize there are alternative ways to represent a date...

Anyway thanks for your links. They were interesting indeed.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Bunce
New Member

Australia
84 Posts

Posted - 14 March 2002 :  06:25:15  Show Profile  Send Bunce an ICQ Message
Very true.

In this case though I've used a number of different 'date methologies' and having encountered many of the problems/issues that I read around the community, I've found the ISO method to be the solution (or prevention) in almost all cases.

If you get the chance Ru, check out the rest of Kens http://www.adopenstatic.com site. Quite interesting and informative. I often list his links in newsgoups etc. as they come up so often. (Plus I can't miss an opportunity to plug a fellow Aussie - He hangs out on the 15Seconds ASP list and a number of the Wrox lists, which are quite popular and useful if you're interested).

Anyway, enough babble - Ciao for now,

Andrew



======================================================
There have been many, many forum posts made throughout the world...
This was one of them!
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 14 March 2002 :  08:07:30  Show Profile  Send ruirib a Yahoo! Message
quote:

If you get the chance Ru, check out the rest of Kens http://www.adopenstatic.com site. Quite interesting and informative. I often list his links in newsgoups etc. as they come up so often. (Plus I can't miss an opportunity to plug a fellow Aussie - He hangs out on the 15Seconds ASP list and a number of the Wrox lists, which are quite popular and useful if you're interested).



Andrew

I had bookmarked adopenstatic. It's interesting enough, indeed. Also done that with 15seconds a while back.
Odd thing that my main ASP book is Wrox's Professional Active Server Pages 3.0 and I almost never go there. I guess you need to be in search of a solution that you don't have to really have the urge to look for it.

Thanks for the new tips.

Ciao to you too.

Rui

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

doog
Starting Member

3 Posts

Posted - 18 March 2002 :  07:06:49  Show Profile
uhm

why don't you use ADODB.Command 's and let ADO do the work of date conversion?

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 18 March 2002 :  07:32:06  Show Profile  Send ruirib a Yahoo! Message
quote:

uhm
why don't you use ADODB.Command 's and let ADO do the work of date conversion?


ADO does no such thing. You don't take proper care you may get your month/day switched or maybe even generate error in date fields.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

doog
Starting Member

3 Posts

Posted - 20 March 2002 :  08:46:49  Show Profile
quote:

ADO does no such thing. You don't take proper care you may get your month/day switched or maybe even generate error in date fields.



Sorry, that is not right

imagine the following example in vb


dim datevar as date
dim cmd as adodb.command
datevar=now

set cmd = new adodb.command
cmd.commandtype = adcmdtext
cmd.commandtext = "update tablename set datecolumn=?"
cmd.parameters.append cmd.createparam("datevalue1", adparaminput, addate, -1, datevar)
set cmd.activeconnection = hCon
cmd.execute

(where hCon is the database connection)
the db provider will handle the datevalue correctly with each kind of db, you do not need to care for it
the second advantage is, when you pass string values this way, the db provider will also take care of ampersants or comment signs
(do not kill me for spelling mistakes in the code, i wrote it by heart)

g

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 20 March 2002 :  08:55:23  Show Profile  Send ruirib a Yahoo! Message

You are forgetting one thing: the date format varies alot according to your locale. It maybe that the client and server settings are different and dates represented differently (month/day/year, day/month/year). If this happens you won't have the date properly written to the DB, in a format acceptable to the client. And this has been the subject of this discussion all along.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs


Edited by - ruirib on 20 March 2002 08:57:00
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 20 March 2002 :  08:56:29  Show Profile  Visit Gremlin's Homepage
Thats a similar solution you've proposed there to whats being discussed. the

cmd.createparm when used with the Addate parameter ... Doesnt actually store a date in the field. It stores the number of days difference between the date you supply and 12/30/1899. So in effect thats also negating the problem of date formats becuase your just using a single number representing the difference in days of 2 dates.

www.daoc-halo.com
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 20 March 2002 :  08:57:42  Show Profile  Visit Gremlin's Homepage
quote:
You are forgetting one thing: the date format varies alot according to your locale. It maybe that the client and server settings are different and dates represented differently (month/day/year, day/month/year). If this happens you won't have the date properly written to the DB, in a format acceptable to the client.


Which is exactly why people have suggested sticking with ISO format for the date, their is absolutely zero ambiguity then.

www.daoc-halo.com
Go to Top of Page

doog
Starting Member

3 Posts

Posted - 20 March 2002 :  09:06:31  Show Profile
but that problem is not too hard to resolve

you send the client locale of the user within the http-post and do a setlocale in before converting the user input into the date variable

so every user can stick with the date format of his own

Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.28 seconds. Powered By: Snitz Forums 2000 Version 3.4.07