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!

Date ControlSource Woes in non-grid controls 2

Status
Not open for further replies.

pt777

Technical User
Mar 27, 2004
62
US
In non-grid field-controls I've used date fields with 'FORMAT'='YL'
(this being Windows long date format). This is rough because of Window's 'Region' variances in Control Panel.

I've tried the below expression and it fails with error message "Not a variable reference":

LEFT(cDOW(myTable.datefield),3)+", "+LEFT(cmonth(myTable.datefield),3)+" "+ALLTRIM(STR(DAY(myTable.datefield)))+", "+right(ALLTRIM(STR(YEAR(myTable.datefield))),2)

Worse yet, when I try to get a VALUE of a date control (in a non-grid control) it always yields the DATE itself instead of the visible value:
i.e., wait window (this.control.value) produces "11/02/2004" instead of the visible value "Tue, Nov 2, 04" (resulting from the YL format).

In sum: I'm searching for a way to make non-grid controls really look like:
LEFT(cDOW(myTable.datefield),3)+", "+LEFT(cmonth(myTable.datefield),3)+" "+ALLTRIM(STR(DAY(myTable.datefield)))+", "+right(ALLTRIM(STR(YEAR(myTable.datefield))),2)

or else for the date-control.width to adjust to "YL" (format).

Thanks always,
Philip
 
Philip,

First, I suggest you avoid setting the Format property to YL. You'll get more reliable results by leaving it blank, and setting Dateformat to 14 instead.

Also, you say:
I've tried the below expression and it fails with error message "Not a variable reference":

LEFT(cDOW(myTable.datefield),3)+", "+LEFT(cmonth(myTable.datefield),3)+" "+ALLTRIM(STR(DAY(myTable.datefield)))+", "+right(ALLTRIM(STR(YEAR(myTable.datefield))),2)


I just pasted this expression in the command window, and it works fine. Have you perhaps made a mistake with the alias or field name?

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Philip, don't know if this will help...

Code:
FUNCTION poshdate
*******************************************************************
* Purpose:    Function to return the date in a formatted string
* Syntax:     <VarC> = poshdate(<ExprD>[,<ExprN>])
* Returns:    Depending on the number and value of the parameters
*             passed, the date will be returned as follows:
*
* Where:      <ExprD> = 15/08/90
*
*             poshdate(<ExprD>) -> "Saturday 15th August 1990"
*             
*             If the optional second parameter is passed poshdate
*             will return the following:
*             
*             <ExprN> = 0 -> "Saturday 15th Aug. 1990"
*             <ExprN> = 1 -> "Saturday 15th August"
*             <ExprN> = 2 -> "Saturday 15th Aug."
*             <ExprN> = 3 -> "Sat. 15th Aug."
*             <ExprN> = 4 -> "Saturday 15th"
*             <ExprN> = 5 -> "Sat 15th"
*             <ExprN> = 6 -> "15th Aug '92"
*             <ExprN> > 7 -> "15th"
*			  <ExprN> = 7 -> "15th August"
* Notes:      <ExprD> must be a valid date
*             <ExprN> must be an integer
*
*******************************************************************
PARAMETERS	pd_date,pd_mode
PRIVATE		pd_day,;
			pd_retval,;
			pd_pcount,;
			pd_suffix,;
			pd_daynum

pd_pcount	= PARAMETERS()
pd_day		= DAY(pd_date)%10
pd_daynum	= DAY(pd_date)
pd_suffix	= IIF(INLIST(pd_daynum,1,2,3,21,22,23,31),SUBSTR(" stndrd",pd_day*2,2),"th")
pd_pcount	= IIF(EMPTY(DOW(pd_date)),0,pd_pcount)

IF pd_pcount = 2
	DO CASE
	CASE pd_mode = 0
		pd_retval	= CDOW(pd_date) + " " + LTRIM(STR(pd_daynum)) + pd_suffix + " " + LEFT(CMONTH(pd_date),3) + ". "+STR(YEAR(pd_date),4,0)
	CASE pd_mode = 1
		pd_retval	= CDOW(pd_date) + " " + LTRIM(STR(pd_daynum)) + pd_suffix + " " + CMONTH(pd_date)
	CASE pd_mode = 2
		pd_retval	= CDOW(pd_date) + " " + LTRIM(STR(pd_daynum)) + pd_suffix + " " + LEFT(CMONTH(pd_date),3) + "."
	CASE pd_mode = 3
		pd_retval	= LEFT(CDOW(pd_date),3) + " " +LTRIM(STR(pd_daynum)) + pd_suffix + " " + LEFT(CMONTH(pd_date),3) + "."
	CASE pd_mode = 4
		pd_retval	= CDOW(pd_date) + " " + LTRIM(STR(pd_daynum)) + pd_suffix
	CASE pd_mode = 5
		pd_retval	= LEFT(CDOW(pd_date),3) + " " + LTRIM(STR(pd_daynum)) + pd_suffix
	CASE pd_mode = 6
		pd_retval	= LTRIM(STR(pd_daynum)) + pd_suffix + " " + LEFT(CMONTH(pd_date),3) + " '" + RIGHT(STR(YEAR(pd_date),4,0),4)
	CASE pd_mode = 7
		pd_retval	= LTRIM(STR(pd_daynum)) + pd_suffix + " " + CMONTH(pd_date)

	OTHERWISE
	
		pd_retval	= LTRIM(STR(DAY(pd_date))) + pd_suffix
	ENDCASE
ELSE
	pd_retval = IIF(EMPTY(pd_pcount),"",CDOW(pd_date)+" "+LTRIM(STR(pd_daynum))+pd_suffix+" "+CMONTH(pd_date)+" "+STR(YEAR(pd_date),4,0))
ENDIF
RETURN pd_retval

Bob Palmer
The most common solution is H2O!
 
Mike, the expression is valid, yes, but not in textbox.ControlSource. I'll research dateformat as you suggest.

Bob, I'm studying your function and will give further feedback if it helps.


Thanks immensely,

Philip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top