We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Excel Cell to contains time value only

Thread ID:





73837 May 22,2008 03:26 AM UTC Jun 10,2008 09:58 AM UTC WinForms 5
Tags: XlsIO
Lim Kek
Asked On May 22, 2008 03:26 AM UTC

The code:

worksheet.Range(XRow, XCol).Value = "12:45:12"

will create a cell in excel with Date & time where the date is defaulted to today date.

How could i modify the code so that the cell in excel will stored only time with no date? Excel does allows cell to have time only value.

Bhuvaneswari P [Syncfusion]
Replied On May 22, 2008 06:16 AM UTC

Hi Limkek,

Thank you for your interest in Syncfusion products.

Yes, it is possible to display Time alone in the cell by setting the custom format. Please refer the below code snippet to do so:

IWorksheet sheet = ExcelWorkbook.Worksheets[0];
//Assign today DateTime
sheet.Range["A1"].DateTime = DateTime.Now;
//Set the time format to display Time only
sheet.Range["A1"].NumberFormat = "HH:MM:SS AM/PM";

Please try this and let me know if this helps you.

Best Regards,

Lim Kek
Replied On May 22, 2008 08:11 AM UTC

Currently i am using the same method that you suggested. Yes, the cell show time only format but the actual value also include today date. Cell in Excel actually allows us to store time value only. It will be very different when this cell is refered by other cell for formula calculation, the result will not be same.

Bhuvaneswari P [Syncfusion]
Replied On May 23, 2008 11:12 AM UTC

Hi Limkek,

Thanks for the update.

If you want the Time alone please use the DisplayText property or if you want both Date and Time then please use Value property of the cell.

//This will return both Date and Time

//This return only the display text, in this case it will return the Time alone.

Please try this and let us know if this helps you.

Best Regards,

Administrator [Syncfusion]
Replied On June 9, 2008 03:28 PM UTC

There several ways to do it:

1) Excel stores time and date in the same way, so there is no difference for between them, just number formatting. You just have to set correct year, month, day.
2) alternatively you can use TimeSpan property from IRange to assign TimeSpan object
3) set correct number ( 1 means 1 day, so 1 hour = 1/24) and assign number format

Yavanaarasi G [Syncfusion]
Replied On June 10, 2008 09:58 AM UTC

Hi Ami,

Thank you for sharing your ideas.

Please let me know if you have any other concerns.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon