Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2008, 01:18 PM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Default Date Value

I am putting together a database for a production line. We run 24/7 and the production cuttoff is at 9:00AM. I am trying to create a field that will contain a default production date. The problem is that between 12:00AM and 9:00AM i need the field to default to the previous day. I've tried several ways to do this but nothing seems to work the way that it should. I think that the default value should be something like this:
Code:
=IIf(Time()>'00:00:00' And Time()<'09:00:00',Date()-1,Date())
Perhaps I am way off?

 
Old September 17th, 2008, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Literal dates and times in Access must be given as #...#

You can't use strings (which is what '....' implies) without invoking a conversion function.

=IIf(Time()>#00:00:00# And Time()<#09:00:00#,Date()-1,Date())

Now, that *MISSES* midnight, since it is 0:00:00 exactly. You would want to use >= instead of >. But then that's silly, because *ALL* TIME() values are always >= #00:00:00#.

So K.I.S.S. and just do

=IIf( Time() < #09:00:00#, Date()-1, Date() )

And you don't want to know this, but... You could also do

=IIf( Time() < 9/24, Date()-1, Date() )

(Don't do it! It will only make your head hurt.)

p.s.: Another thing not to do, but you could do

=IIf( Time() < CDate('09:00:00'), Date()-1, Date() )

As I said, if you use a string you must use a conversion function.

p.p.s.: On the other hand, you could reasonably do

=IIf( Hour(Time()) < 9, Date()-1, Date() )
 
Old September 17th, 2008, 04:20 PM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

D'OH
Now my head hurts.

Thanks for the advice!






Similar Threads
Thread Thread Starter Forum Replies Last Post
DATE / TIMESTAMP default values WarHead MySQL 2 April 20th, 2006 10:18 AM
Change default date parameter format JeffHickman Reporting Services 0 February 14th, 2006 06:52 AM
DTS Import ( Date string to Date field) gfowajuh SQL Server 2000 1 September 30th, 2003 06:28 AM
Default Value = Todays Date cej2583 SQL Server 2000 2 July 28th, 2003 10:55 PM
Convert String Date to Date for a SQL Query tdaustin Classic ASP Basics 4 July 7th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.