|
-
Nov 11th, 2007, 09:51 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]How can I multiply a date
Hello,
It's me again...How can I multiply a date like for example I have 14/12/2004 on a dd-mm-yyyy format. On my code I want it to multiply it by term and every term composed 1 month. and I want to display it again into the same form dd-mm-yyyy format.
Ex. 14/12/2004 * 12 = 14/12/2005 ' I want to get this
Thanks a lot of you guys out there
Last edited by shyguyjeff; Nov 27th, 2007 at 10:11 PM.
-
Nov 11th, 2007, 10:14 PM
#2
Re: How can I multiply a date
Firstly, you don't have a date in any format because Date objects have no format. Format is only an issue when displaying a string representation of a date, which you certainly aren't doing when performing mathematical calculations on that Date.
Secondly, multiplying a date makes no sense whatsoever. You might perform addition or subtraction on a date, but certainly not multiplication or division. In your case you're performing addition, i.e. adding 12 months:
vb.net Code:
myDate = myDate.AddMonths(12)
Like I said, that date object has no format. If you want to display it to the user you would convert it to a string and display that. It is THEN AND ONLY THEN that format becomes an issue:
vb.net Code:
myLabel.Text = myDate.ToString("dd-MM-yyyy")
That said, I strongly recommend that you do not force your preferred date format on the user. Windows allows each user to specify exactly how they want to have dates displayed and you should respect the user's choices wherever possible. To use the system date format selected by the user in the OS options you'd do this:
vb.net Code:
myLabel.Text = myDate.ToShortDateString()
Now a US user won't get confused because you've forced the day to be shown first when they expect to see the month first. Everyone will see exactly what they expect to see, as is appropriate.
-
Nov 11th, 2007, 10:22 PM
#3
Frenzied Member
Re: How can I multiply a date
 Originally Posted by jmcilhinney
That said, I strongly recommend that you do not force your preferred date format on the user. Windows allows each user to specify exactly how they want to have dates displayed and you should respect the user's choices wherever possible. To use the system date format selected by the user in the OS options you'd do this:
My preference is to always display dates in the format "dd MMM yyyy" which overcomes any BA ambiguity.
-
Nov 11th, 2007, 10:50 PM
#4
Thread Starter
Hyperactive Member
Re: How can I multiply a date
tnx guys out there....it helps ........especially to jmcilhinney...
-
Nov 14th, 2007, 09:03 PM
#5
Thread Starter
Hyperactive Member
Re: How can I multiply a date
guys need follow up on my problem....The code works smoothly but how about if I add months that has already date from my database like this 7/10/2006 12:00:00 AM then i want to add moths...is it possible? How can I do that?
Regards,
Jeff
-
Nov 14th, 2007, 09:13 PM
#6
Re: How can I multiply a date
Its the same as JCM showed you. Are you casting you dates from your databases into strings?
-
Nov 14th, 2007, 09:15 PM
#7
Re: How can I multiply a date
A Date is a Date. If you get a date value from a database then it's stored in a Date. You already know how to add a number of months to a Date. I assume that you already know how to save updates to a database too but, if you don't, follow the Data Access Examples link in my signature.
-
Nov 14th, 2007, 10:27 PM
#8
Thread Starter
Hyperactive Member
Re: How can I multiply a date
 Originally Posted by wild_bill
Its the same as JCM showed you. Are you casting you dates from your databases into strings?
I am casting from my database and put it in a Textbox....But when I add a months on it. I have 3 textboxes..txtBoxTerm, txtBoxStartDate, txtBoxEndDate..When I add the txtBoxTerm on my txBoxStartDate it result in into txtBoxEndDate...This is my problem to get the txtBoxEndDate...Tnx bill..
@jm
tnx jm...ur work is nice...it helps me but sorry if sometime i understand it so hard sometimes..I am just a newbie in programming thats why i keep on asking...Thanks again...God Bless...
-
Nov 14th, 2007, 11:11 PM
#9
Re: How can I multiply a date
You shouldn't be adding anything to the value in the TextBox. That's a String, not a Date. What you should be doing is storing the value from the database in a Date variable. You can, at any point, display that value in a TextBox. If you want to add a number of months then you add them to the Date value, then display that new value in the TextBox again.
-
Nov 14th, 2007, 11:59 PM
#10
Thread Starter
Hyperactive Member
Re: How can I multiply a date
I made it!!!!!!!!!!!!Yepeeeeeeeeehhhhh!!!!!!!!!Thanks jm....your a great wizard!!!!!!!!!Hurrahhh!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|