Solved

Rant: Date()+3 days into database

Posted on 2001-06-28
5
330 Views
Last Modified: 2012-06-27
I want to write the current date plus a number of days into a DB (using ADO, JScript)

What I've come up is this:

// a) Add three days
var now = new Date();
expires = new Date( now.valueOf + days * 1000 * 60 * 60 * 24);

// b) write to db - parametrized query:
//    using VT_DATE (adDate) type
Command.CommandText = "Insert INTO ... (...,?,...)
Command.CommandType = ...

Command.Parameters.Append(
  Command.CreateParameter("foo", 7 /*adDate*/, 1 /*adParamInput*/,
8, expires.getVarDate());

It works, almost, to say the best.

a) the crude way to add the n days to now makes me feel uneasy. Isn't there a better way?

b) Same for adding to insert statement. The Time part get's truncated (i.e. only the date part is written to DB). I can't use a string, like expires.toLocaleString, because this gores over the hill if the locales of OS and JetDB differ.

(e.g. MS Access german, and OS/IIS is English -> July 2nd, which is 07/02/2001 in US locale, is parsed happily as Feb 07, 2001.)

I could create a string in adDBTimeStamp from the date - but this requires a whole lotta hell of instructions that don't seem worth it.

Is Date Handling always that terrifying as soon as you leave US, or do I miss the obvious?


100 pts for a "straightforward" solution, or if you can make me giggle about all this date stuff.

----------

Warning: life may offend
0
Comment
Question by:peterchen092700
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:nilapenn
ID: 6237051
var numofdays=10
var curdate=new Date()
var newdate=new Date(curdate.setDate(curdate.getDate()+ numofdays))
0
 
LVL 5

Expert Comment

by:nilapenn
ID: 6237137
var numofdays=10
var curdate=new Date()
var newdate=new Date(curdate.setDate(curdate.getDate()+ numofdays))
0
 
LVL 20

Accepted Solution

by:
Silvers5 earned 100 total points
ID: 6237450
hmm.. you can add directly in the sql query string

"Insert into tablename (...,DateAdd) values (...,GetDate() + 3)"
0
 
LVL 7

Author Comment

by:peterchen092700
ID: 6249635
Silvers: perfect idea! (Although MS Access knows only Date(), not GetDate()...) Although it doesn't cure the braindead date-handling, it saved my day!

Peter
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6251285
well get date is for sql.. you can use now and date in access..

thanks ;o)
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question