Take the 2-minute tour ×

The date time displays as 07/10/2011 01:29:20 I want to display only 07/10/2011 01:29 how can I do that.

     DateTime now = DateTime.Now.AddHours(12);
        txt_ExpiresBy.Text = Convert.ToString(now);

And I have this datetime calendar which I assign it to a text box, I have to assign this calendar to 3 text box, How can I do it. Should I use three Javascript with different name or can I do with this below?

<script type="text/javascript">

        $(function () {

<asp:TextBox ID="forDatePicker" runat="server" />
share|improve this question
add comment

3 Answers

up vote 1 down vote accepted
txt_ExpiresBy.Text = expirestime.ToString(@"dd/MM/yyyy hh:mm");

The Datetime.ToString() method is pretty flexible or you can use one of the other methods such as ToShortDateString().

See the MSDN docs for more details: http://msdn.microsoft.com/en-us/library/system.datetime.aspx

Using the class name to assign the datetimepicker to multiple textboxes should work just fine.

share|improve this answer
Thanks that works –  John Oct 6 '11 at 12:36
@John - No problem. I updated the answer to specifically address your required format. –  Geoff Appleford Oct 6 '11 at 12:41
add comment

Use DateTime.ToString() method.

DateTime expirestime = expirestime.AddHours(12);
txt_ExpiresBy.Text = expirestime.ToString();
share|improve this answer
add comment

with overload ToString Method

this.txt_ExpiresBy.Text = DateTime.Now.ToString("dd/mm/yyyy" + " " + "hh:mm");


share|improve this answer
add comment

Your Answer


