Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

Tuesday, December 21, 2010

Find Age

To Find the age of a person there is another class avaliable in VS
C#

TimeSpan
Datetime myBirthday=DateTime.Parse("7/7/1982");
TimeSpan objTimeSpan=DateTime.Now.Subtract(myBirthDay);

Friday, August 27, 2010

Get Date From DateTime In SQL

Get Date From DateTime In SQL
Something I need to do from time to time is get just the date part of a datetime value in SQL. I found a cool way to do it on SQLJunkies today.

select convert(varchar,DateColumn,101)

The 101 means “mm/dd/yyyy” format, but there are a bunch of other codes you can use. 108 will return just the time “hh:mm:ss” for instance.

Update: 101 includes 4 digit year 'yyyy'. A code of 1 would apparently be "mm/dd/yy", according to user comments.

Thursday, June 24, 2010

Read /write NULL Datetime in Sql Server by C#

When you have to insert or read NULL datetiem from sql server then in that case.

Use Namespace:using System.Data.SqlTypes;

declare a variable SqlDateTime sqlNullDate;

for INSERT
if (txtSessionStartDate.Text == "")
sessionsOBJ.sDate = sqlNullDate;
else
sessionsOBJ.sDate = Convert.ToDateTime(txtSessionStartDate.Text);

and read would work normally.