INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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

RE: Show only DATE portion of a DATETIME field in a text box

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

RE: Show only DATE portion of a DATETIME field in a text box

Set textbox.controlsource = "(TTOD(datetimefield))"

Bye, Olaf.

RE: Show only DATE portion of a DATETIME field in a text box

(OP)
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.


RE: Show only DATE portion of a DATETIME field in a text box

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close