Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String variable to retain miltary format from sql database??

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
The datetime data in MS-SQL is stored as miltary format but when I retrieve it from the database and assigned it to string, it get converted to standard format. I don't want standard format, i want it unchanged leaving it as military format.

Thanks...

Code:
sAsk = "";
sAsk += " SELECT CAST(LoginTimestamp AS DATETIME) AS LoginTimestamp FROM tblWebUsers_LoginManagement ";
sAsk += " WHERE UserID = '" + sUserId + "' ";
bSuccess = this.ftnDatabase_SelectQuery_DataSetFiller(sAsk, ref oDataSet, ref sErrorMsg);
if (bSuccess == false)
{
   throw new Exception("Unable to retrieve data from database");
}
if (oDataSet.Tables[0].Rows.Count > 0)
{
   sOldLoginTimestamp = Convert.ToString(oDataSet.Tables[0].Rows[0]["LoginTimestamp"]);
}
 
date data is stored as a datatime value. how you display this value is up to you. to control the formating using the tostring() override of the datetime object.
Code:
var currentTime = DateTime.Now;
var military = currentTime.ToString("MM-dd-yy HH:mm:ss");

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top