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

Show only DATE portion of a DATETIME field in a text box 2

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi friends,

I have a form with a text box which is bound to a DATETIME field in a table. When the form is shown, I want to show only the DATE portion of that DATETIME field in the text box. I use BRITISH format. I tried changing the 'Format' property of the text box to '99/99/9999'. But it seems, it doesn't work. It doesn't gives any error, but the textbox still shows the field as DATETIME format only.

Anyone has any idea?

Thanks in advance
Rajesh
 
Use the TTOD() function to convert it first.

ldDateOnly = TTOD(Table.DATTIMEFIELD)

This.Value = ldDateONly


Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Dear Olaf,
That was excellent! Tried and it works! I had earlier tried typing 'TTOD(datetimefield)' but it didn't accept it. Now, as you showed, with outside brackets it works. However, as I am using the same controlsource for record entry also, I change the controlsource at runtime, ie for new entries full datetime but for existing entries with TTOD.
Thank you very much.

Dear Scott,
Thank you for your reply. But, it was not working. May be, as I have the field as controlsource. Too, I think I could not have used VALUE property as I am using the same textbox and field combination for data entry also.


 
Yes, if the controlsource is a datetime and you set the value to a date, that's automatically "upsized" to a datetime. The same happens, if you insert a DATE() into a datetime column. There are many implicit conversions taking place. The major factor determining the displayed type is not the value, but the controlsource type.

And yes, this way of setting an expression works readonly, that expression can't be updated from the control. For some reason since I think VFP7 you need the extra brackets, though TTOD(field) surely can't mean a variable or field or property, at most an element of a ttod array, but that would require the field as array index to be a numeric type. Surrounding any expression with brackets ensures VFP to know you mean an expression.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top