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

DATE()

Status
Not open for further replies.

ferdinandpagayatan

Programmer
Jul 14, 2015
7
0
0
PH
how to add date to another date in my textbox
ex:

07/15/2015 + 07/25/2015=?

and how to add datepicker only in my forms.
thanks and more power.
 
Mathematically speaking, this operation is undefined.
You must decide what the result must be.

You can
- add each component (year + year, month + month, day + day)
- add only one part (e.g. the day of the second date to the first date)
- add the corresponding number of days between 1/1/1 A.D and each date, and convert back the result into a date
and so on

After you do that, is not quite complicated.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
You can add two apples, but that will not be one larger apple, it's still two apples. What do you expect to get, when adding two dates? It's good this gives an error. What should the result really be?

What you can do is compute the date in two weeks, eg DATE()+14, or the date next month GOMONTH(DATE(),1).
What you can do is compute the difference in days between two dates, eg DATE()-DATE(1999,12,31) will give you the number of days we survived the Y2K problem.

Bye, Olaf.
 
Perhaps if we better understood what you are really trying to do, we could give you the best answer.

As you have been advised above, you can add Days to a specific Date
Code:
nDays = CTOD('07/25/2015') - CTOD('07/15/2015')
dNewDate = CTOD('07/15/2015') + nDays  && This example is somewhat meaningless since it would result in the latest date again

Let us know what you are trying to achieve.

Good Luck,
JRB-Bldr

 
Just to add a word ....

The title of your post is simply DATE(). Be aware that the DATE() function does not itself perform date arithmetic. Instead, it returns a value in date format. You can pass the year, month number and day number (within month), in that order, and it will return the corresponding date. For example, DATE(2015, 7, 16) returns 16th July 2015. If you omit the parameters, it returns today's date.

Beyond that, it's difficult to answer your question without knowing what exactly you are trying to achieve.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
jrbbldr, I think you wanted to wrte something else in your code section. The first - should be = in each line to make sense.
You could correct it.

Edit: Fine, now it works. Edit is a nice feature, isn't it?

Bye, Olaf.
 
* You could add two dates as follows but there is no reason to do so as per my imagination.

d1 = date(2015,07,15)
d2 = date(2015,07,16)
NewDate = sys(10,val(sys(11,d1)) + val(sys(11,d2)) ) && Max date 9999/12/31


* I guess you want to add difference of two dates to the current date or something similar.
* for example:

NewDate = date() + (d2 - d1)


Nasib
 
for example i have a form.

employee:
postion:
training attended:
from: december 12, 2014
to: december 20, 2014
# of days: ~this is what i want to get the answer from the two dates above.

thanks a lot.
 
Do you want to subtract one date from another? To get the number of days between the two dates?

If so, it's sinmple:

Code:
NumberOfDaysBetween = SecondDate - FirstDate

For example:

Code:
ldFrom = DATE(2014, 12, 12)
ldTo = DATE(2014, 12, 20)
lnNumberofDays = ldTo - ldFrom

Does that answer your question?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I already showed in my first answer how subtracting two dates results in the number of days between them.
Anyway, if you want a difference, why do you think adding dates would give a difference?

One more thing to be aware of, if your dates are actually datetimes, the difference will be a vast number, because then the difference will be in seconds.
Take a look at TTOD then, to get dates first.

Bye, Olaf.
 
* Example :
* Assuming you have TextBox type inputs as follows
* FromDate - From Date
* ToDate - To Date
* NumOfDays - # of Days

* in the init() of the form, add following 4 lines of code.
thisform.NumOfDays.Enable = .f.
thisform.FromDate.value = date()
thisform.ToDate.value = date() + 1
thisform.NumOfDays.value = Thisform.ToDate.value - thisform.FromDate.value

* in the lostfocus() events of FromDate and ToDate, insert the next code
if empty(thisform.Todate.Value) or empty(thisform.FromDate.value)
thisform.NumOfDays.value = 0
else
thisform.NumOfDays.value = thisform.ToDate.value - thisform.FromDate.value
endif

* When you will make a change on your form in the FromDate or ToDate, NumOfDays will reflect the difference.
* I hope this may help.
*

nasib
 
download.aspx
 
 http://files.engineering.com/getfile.aspx?folder=f6cecfee-4cb6-4e9a-978d-2757968522b8&file=Untitled.png
OK, so you've got a form with a "From" date and "To" date, and a field showing a number of hours.

So what is your question? Are you asking how to calculate the number of hours between the From and To dates?

If so, we have already given you the information you need:

To determine the number of days between the two dates, subtract the From date from the To date (which, in this case, are Text4.Value and Text5.Value respectively).

To determine the number of hours, multiply the number of days by the number of hours in a day. Then store that result in the relevant field (Text6.Value).

(This assumes that Text4 and Text5 are date fields.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Everyone is struggling to figure out what is your question.
Is it syntax or logic issue ?

To find out the number of days (the only extra piece of information as from your screen shot), you need to add 1 to the diffrence to take care of the inclusive parameter.



 
its ok now. thank you very much for the info.

text5 - InteractiveChange

PUBLIC ldStartDate
PUBLIC ldOtherDate
ldStartDate = this.Value
ldOtherDate = thisform.text4.value
n=ldStartDate - ldOtherDate + 1
thisform.text6.value=n*8
thisform.text2.Value=n
 
 http://files.engineering.com/getfile.aspx?folder=11ac3e6f-8b7c-4cfb-be18-0dcede9c9232&file=Untitled.png
Sir i want to learn more on DatePicker in foxpro any one can teach me?

Please post this as a new thread.

And when you do, please ask a specific question in plain language that everyone can understand. We spent a lot of time answering your first question because you didn't explain what you needed to know.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top