Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

Rant: Date()+3 days into database

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
peterchen092700
Asked:
peterchen092700
  • 2
  • 2
1 Solution
 
nilapennCommented:
var numofdays=10
var curdate=new Date()
var newdate=new Date(curdate.setDate(curdate.getDate()+ numofdays))
0
 
nilapennCommented:
var numofdays=10
var curdate=new Date()
var newdate=new Date(curdate.setDate(curdate.getDate()+ numofdays))
0
 
Michel SakrCommented:
hmm.. you can add directly in the sql query string

"Insert into tablename (...,DateAdd) values (...,GetDate() + 3)"
0
 
peterchen092700Author Commented:
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
 
Michel SakrCommented:
well get date is for sql.. you can use now and date in access..

thanks ;o)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now