---
title: "Date & time not displaying correctly"  
description: "Date & time not displaying correctly"  
author: "Anonymous User"  
published: 2013-12-18  
updated: 2013-12-18  
canonical: https://www.mindstick.com/forum/1816/date-time-not-displaying-correctly  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Date & time not displaying correctly

I am creating my first win [form application](https://www.mindstick.com/interview/23108/how-to-create-form-application-using-dot-net), written in C#. I have added a little bit of code to display the [current date](https://www.mindstick.com/forum/323/find-the-day-name-and-month-name-from-current-date) and time on the first tab page as below:

[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) void Form1_Load(object sender, EventArgs e)

{

// [connect](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) to [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax)

c = new [Connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi)();

connect.ConnectionString = c.getConnection();

//deals with date and time

[Timer](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) tmr = new Timer();

tmr.Interval = 1000;//ticks every 1 [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society)

tmr.Tick += new EventHandler(tmr_Tick);

tmr.Start();

}

private void tmr_Tick(object sender, EventArgs e)

{

labeltime.Text = DateTime.Now.ToString(" Todays Date: dd/MM/yyyy\n\n Current Time: HH:mm:ss");

}

The [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) in not correct however. The date and time are correct and ticking away nicely but where I want it to display "Todays Date:" it is messy like " To15a1342 (42 being the seconds from the time, ticking away) and the "Current Time" reads CuRRenP Ti50e:

Does it matter that I am in the UK? Would this require me to use different code or something?

## Replies

### Reply by Anonymous User

Hi Samuel,

Your text is being interpreted as formatting strings, as explained in DateTime.ToString(string format):

The format parameter should contain either [...] a custom format pattern (see Custom Date and Time Format Strings)

Only unrecognized characters are printed as-is, but as you noticed for example the s gets replaced by the value of Seconds.

To let ToString() ignore your text, you need to escape the literals, preferably with single quotes (') (the alternative is a backslash in front of each literal):

string dateTimeString = DateTime.Now

.ToString("' Todays Date: 'dd/MM/yyyy'\n\n Current Time: 'HH:mm:ss");

Or build up the string from separate parts:

var now = DateTime.Now;

string dateTimeString = "' Todays Date: ";

dateTimeString += now.ToString("dd/MM/yyyy");

dateTimeString += "\n\n Current Time: ";

dateTimeString += now.ToString("HH:mm:ss");

Above string concatenation example can in turn be simplified as @Rohit's answer demonstrates.


---

Original Source: https://www.mindstick.com/forum/1816/date-time-not-displaying-correctly

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
