Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates Again!

Status
Not open for further replies.

Muzzy

Programmer
Dec 14, 2001
68
GB
Currently I have a field on a form (txtDate)that displays todays date, I then have another field that picks out the month in that date(txtMonth)and displays it e.g September. I then want to say if that month = September(For example) then the value of a different field (txtQuarter) has to be set to '2'.

From what I can gather the field named txtMonth stores the date as 01/09/02 and just pick the month out and displays September so the field will never = September!
Any helpers?
 
Hi Muzzy

I'm not sure what you've got there but month(datefield) will give you the month number (1 - 12). You could try using this and then converting the number afterwards

Tom
 
This is a bit crude but it'll do the job

----------------------

Private Sub WhateverAction()

Dim quarter As Integer

txtmonth = Month(txtdate)

Select Case Month(txtdate)

Case Is < 4
quarter = 4

Case Is < 7
quarter = 1

Case Is < 10
quarter = 2

Case Is < 12
quarter = 3

End Select

txtquarter = quarter
End Sub
 
How about:

txtQuarter = DatePart(&quot;q&quot;, txtDate)

txtMonth = Format(Month(txtDate),&quot;mmmm&quot;)

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
This is the proper control source for txtMonth:

=Format([txtDate],&quot;mmmm&quot;)

You can use a switch to display whatever criteria you want in txtQuarter. Set the control source for txtQuarter to something similar to:

=Switch([txtMonth]=&quot;January&quot;,&quot;Quarter 1&quot;,[txtMonth]=&quot;February&quot;,&quot;Quarter 1&quot;,[txtMonth]=&quot;March&quot;,&quot;Quarter 1&quot;,[txtMonth]=&quot;April&quot;,&quot;Quarter 2&quot;,[txtMonth]=&quot;May&quot;,&quot;Quarter 2&quot;,[txtMonth]=&quot;June&quot;,&quot;Quarter 2&quot;,[txtMonth]=&quot;July&quot;,&quot;Quarter 3&quot;,[txtMonth]=&quot;August&quot;,&quot;Quarter 3&quot;,[txtMonth]=&quot;September&quot;,&quot;Quarter 3&quot;,[txtMonth]=&quot;October&quot;,&quot;Quarter 4&quot;,[txtMonth]=&quot;November&quot;,&quot;Quarter 4&quot;,[txtMonth]=&quot;December&quot;,&quot;Quarter 4&quot;)

Have fun,

VBSlammer
redinvader3walking.gif
 
It's not really necessary to go thru a lot
of gyrations to return the quarter of a
particular date. The DatePart function
will do it for you. Try this from the
debug window:
Code:
dteMyDate = date()
? dteMyDate
9/18/02 
? DatePart(&quot;q&quot;,dteMyDate)
 3

This solution assumes that the FY
corresponds to the calendar year. If,
however, the FY starts with a month
other than January (eg, July), you can use
this:
= int(Datediff(&quot;m&quot;,[FYStart],[dteMyDate])/3) + 1

From the debug window, using the previous
example, it would look like this:
Code:
? int(Datediff(&quot;m&quot;,#07/01/02#, dteMyDate)/3) + 1
 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top