Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: Time Database Columns in .NET

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: Thu, Dec 02, 2010, 10:43 AM


Overview

With SQL Server 2008 came (among other things), a new data type: time. By default a time field gets imported into Visual Studio as a TimeSpan .NET type. However, the TimeSpan type doesn't format in the familiar way that a DateTime does. This article describes how to format a TimeSpan using the same format string as for a DateTime.

Code

TimeSpan ts = new TimeSpan(14, 43, 00);
DateTime dt = DateTime.Today.Add(ts);
string s = dt.ToString("h:mm tt");

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.