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!
  • Students Click Here

*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.

Students Click Here


Date Calculations

Date Calculations

Date Calculations

Can somebody teach me on how to calculate a date in visual fox pro 9.0. For example. When i enter a date of PO "10-10-18 " In another text box , automatically compute the due date which is 11-10-18. How can i do that? Thank you for your response. I am newbie in visual vfp.

RE: Date Calculations

ldDateDue = ldDateInvoice + lnDatesCredit 

RE: Date Calculations

Assuming that your dates are stored with the Date datatype (as opposed to a Character data type that contains digits that happen to represent a date), then you can simply add or subtract a number from one date to get another date. So in this case, you would simply add 1 to the order date to get the due date.

If the dates are stored in textboxes, you use the Value property of the textbox to set or get the date, so you could do something like the following:

THISFORM.Text2.Value = THISFORM.Text1.Value + 1

If the textboxes contain Character data, then it is more difficult, as you would have to convert the characters to a valid date, and that involves knowing the date format (MM/DD//YY, DD-MM-YYYY, etc) and how to handle two-digit years.


Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Date Calculations

I interpret your question as asking how to convert a text date to a date value.

Well, there's CTOD() for that, but it's easiest if you bind a textbox to a field or property being a date or initialize the value (simply set the textbox.value in the designer in the property sheet) to a date.
For example right click on the textbox for date entry, select "Properties..." from the context menu and then in the Data Tab in the Value property enter =DATE() and the textbox is initialised to the current date.

Once a textbox displays and has a date value, you can only enter valid dates and textbox.value will be a date, no need to convert it.

CTOD could be relevant to transform data you get as text, it depends on settings of SET DATE, SET MARK TO (caution, there are other SET MARK commands about menu items) and SET CENTURY, there is no automatism to take any text that could resemble a date and convert it and since some formats are month first, others day first, there are ambiguous dates, so you have to first set the way you want dates to display and then you can also reverse texts in that format to dates.

The preferred way to specify dates in code, for example, that is independent of settings is either call DATE() or DATETIME(). Without parameters they provide the values of today and now, parameters allow you to specify a specific date, eg DATE(1999,12,31) but besides needing to call a function date literals are possible in the form {^yyyy-mm-dd}, so you can code datevar = {^1999-12-31}, this also works independant on what the current MARK setting is, even if you have other countries marks like / or . you can always use the dash here and just like DATE() the date literals only allow ymd order. Caution and notice: The string "{^1999-12-31}" doesn't automatically convert into a date, you really write curly brackets as delimiters in code and when you enter such a literal into a textbox that does not come out as such a date but such a string, you can EVAL("{^1999-12-31}"), though, to get that as the date it means.

Besides that, you can compute with dates, like DATE()-7: Date a week ago, DATEIME()+60: DateTime in a minute. GOMONTH(DATE(),1): Date in a month (look into the help topic about how 31 turns into 30 of next month, for example and other special cases).

Bye, Olaf.

Olaf Doschke Software Engineering

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!

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