PC Review


Reply
Thread Tools Rate Thread

Calculate seasons from a date field

 
 
Michael Winn via AccessMonster.com
Guest
Posts: n/a
 
      7th Jan 2005
I am trying to create a calculated field in a query that will give me seasons. I have a field with dates [DATE] and I want to know if that date falls in Winter, Summer, Spring or Fall. I have the data (Spring begins on MAR 21, Summer begins on JUN 21, Fall begins on SEP 23, and Winter begins on DEC 21) but I am not sure how to put it all together so I can create a season field from the date field. Thanks for your help. Mike

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      7th Jan 2005
Michael Winn via AccessMonster.com wrote:

>I am trying to create a calculated field in a query that will give me seasons. I have a field with dates [DATE] and I want to know if that date falls in Winter, Summer, Spring or Fall. I have the data (Spring begins on MAR 21, Summer begins on JUN 21, Fall begins on SEP 23, and Winter begins on DEC 21) but I am not sure how to put it all together so I can create a season field from the date field.



You can calculate the season in a variety of ways. A quick
and dirty method is to use the Switch function:

Switch(Format([Date],"mmdd") < "0321","Winter",
Format([Date],"mmdd") < "0621","Spring",
Format([Date],"mmdd") < "0923","Summer",
Format([Date],"mmdd") < "1221","Fall", True, "Winter")

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
 
 
 
MGFoster
Guest
Posts: n/a
 
      7th Jan 2005
Michael Winn via AccessMonster.com wrote:
> I am trying to create a calculated field in a query that will give me seasons. I have a field with dates [DATE] and I want to know if that date falls in Winter, Summer, Spring or Fall. I have the data (Spring begins on MAR 21, Summer begins on JUN 21, Fall begins on SEP 23, and Winter begins on DEC 21) but I am not sure how to put it all together so I can create a season field from the date field. Thanks for your help. Mike
>


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Access 2002:

Perhaps the DatePart() and Switch() functions. This evaluation will
only work in a query:

SELECT
Switch(DatePart("y",[Date]) Between 81 And 172, "Spring",
DatePart("y",[Date]) Between 173 And 266, "Summer",
DatePart("y",[Date]) Between 267 And 355, "Fall",
DatePart("y",[Date]) Between 356 And 366 OR
DatePart("y",[Date]) Between 1 And 80, "Winter" ) As Season,
....
FROM ... etc.

The "y" interval indicates we want the Day of the Year.

The only problem is leap-year, which is why I put 366 as the ending day
of year. But, it may be better to put a separate Switch() evaluation on
leap years:

If Year([Date]) Mod 4 = 0 Then
... do leap year days
Else
... do non-leap year days
End If


--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQd7heYechKqOuFEgEQLyFgCfbJkuysAxkM9oGAB/R5NppHOo+2gAoMrD
O9C9N2eJZUv5WJ2qUvL1HGTo
=lM0H
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Michael Winn via AccessMonster.com
Guest
Posts: n/a
 
      7th Jan 2005
Thank you very much.

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seasons Greetings =?Utf-8?B?SmVzc2llIHRoZSBmbG93ZXIgb2YgRHVuYmxhbmU= Windows XP Basics 0 24th Dec 2004 02:55 AM
Attire for all seasons!!!!!!!!!!!!! Windows XP General 0 8th Aug 2003 05:38 PM
Attire for all seasons!!!!!!!!!!!!! Windows XP Internet Explorer 0 8th Aug 2003 05:38 PM
Attire for all seasons!!!!!!!!!!!!! Microsoft Access Form Coding 0 8th Aug 2003 05:37 PM
Attire for all seasons!!!!!!!!!!!!! Microsoft Access Forms 0 8th Aug 2003 05:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:01 PM.