Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TextBox inside it a date dd/MM/yyyy format
I have a button when clicked I want to add one day to the date found in the textbox.

Example TextBox: 15/09/2013 When I click I want the textbox text be 16/09/2013

I used this code below but it started adding month when published on server:

VB
date_add.Text = CDate(date_add.Text).AddDays(1).ToString("dd/MM/yyyy")
Posted
Comments
♥…ЯҠ…♥ 12-Nov-13 9:00am    
Server machine DateTimeFormatInfo culture is same as your local machine culture?
[no name] 12-Nov-13 9:17am    
Currently I'm hosting the application on my pc. What is strange is that it is working fine on local host when I open the one on IIS it got confuse the date with the month.
♥…ЯҠ…♥ 12-Nov-13 9:26am    
Try this http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.datetimeformatinfo(v=vs.110).aspx

VB
Private Sub MyButton_Click(sender As Object, e As EventArgs) Handles MyButton.Click
   Dim culture As New CultureInfo("fr-FR", false) '' Here I took french culture because I'm sure it represents the DateTime format the way you want, i.e. dd/MM/yyyy
   Dim myDate As DateTime
   myDate = DateTime.Parse(date_add.Text, culture)
   date_add.Text = myDate.AddDays(1).ToString("dd/MM/yyyy")
End Sub


Hope this helps
 
Share this answer
 
You can use this to subtract and add days to the existing data may be in your in a text box. Once you use these methods you get the values and u can print them or you can set teh text box with a fresh value.

XML
using System;

class Program
{
    static void Main()
    {
    Console.WriteLine("Today: {0}", DateTime.Today);

    DateTime y = GetYesterday();
    DateTime z = GetTomorrow();
    Console.WriteLine(y,z);
    }

    /// <summary>
    /// Gets the previous day to the current day.
    /// </summary>
    static DateTime GetTomorrow()
    {
    // Add 1 to now
    return DateTime.Today.AddDays(1);
    }

    static DateTime GetYesterday()
    {
    // Add -1 to now
    return DateTime.Today.AddDays(-1);
    }

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900