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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the weekday from a 3 part date string

Status
Not open for further replies.

tchekote

Technical User
Aug 19, 2003
7
CA
Hi

I am using visual foxpro 6
I do not know much about programming in databases...


I have a form ".frx that dislpays date and holiday data from a .dbf file.

I want to use the displayed information to return the week day as in monday to sunday.

The expression used to get the date is "alltrim(str(year,4)+"/"+str(monthr,2)) + "/" + alltrim(str(dater))" the return data is 2012/5/28, I want to get the weekday out of it.

the data comes from 3 different fields. year, month and date.

Can you help me?

Thank you



 
Yes, this is easy. First, get the date as a date (rather than a string):

ldDate = DATE(year, month, dater)

(I assume "dater" holds the day number.)

Then, to get the day of the week, use the the DOW() funtion:

lnDayOfWeek = DOW(ldDate)

This will give the day number, where Sunday is 1, and so on.

If you want the day as a word ("Sunday", etc), do this:

lcDay = CDOW(ldDate)

In the above examples, ldDate, lnDayOfWeek and lcDay are just ordinary variables.

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
thank you Mike...

I am using report designer, where and how would I insert these commands...

Sorry I rellay do not know much about this...

Thank you

 
In the report designer, create a new field. In the Expression box, enter something like this:

CDOW(DATE(year, month, dater))

That will cause the day of the week (as a string) to appear in the report.

Give it a try, and come back if it doesn't work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

I did as you instructed


when I click "verify"
it gives me the error variable 'DATER'is not found.

thank mike



 
You indicated that the name of the field containing the day of the month was DateR. Maybe that's not correct?

Tamar
 
it is but it is NOT a date field it is a numeric field. I dont know if that makes a difference.

the 3 fields in question are

year = numeric, width 4
monthr = numeric, width 2
dater = numeric, width 2

the expression i am getting the date from is "alltrim(str(year,4)+"/"+str(monthr,2)) + "/" + alltrim(str(dater))"

is 'dater' a field or a variable....



Thank you

 
GOT IT....
it is working

thank very much everyone...

I really appreciate it...

Cheers






 
The likely reason for the error message was that the table containing DateR was not open while you were working in the report designer. It is at the time you click "Verify" that it couldn't find the field or variable in question.

Often, you can safely ignore that kind of error. Provided the table is open (and selected) at the time you run the report, it should work OK.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top