1
Answer

C++ DateTime to and from C#

Photo of Robert Winslow

Robert Winslow

17y
17.8k
1

I had a need to convert c++ time_t to C# DateTime and have also had the same need to convert to C# DateTime to c++ time_t.

I hope some of you find these conversions useful

[code]

public static long ToUnixtime(DateTime date)

{

DateTime unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);

TimeSpan timeSpan = date - unixStartTime;

return Convert.ToInt64(timeSpan.TotalSeconds);

}

public static DateTime ToCSharpTime(long unixTime)

{

DateTime unixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);

return unixStartTime.AddSeconds(Convert.ToDouble(unixTime));

}

[/CODE]

 

Answers (1)

0
Photo of Muralidharan Deenathayalan
NA 11.9k 1.5m 12y
Here is another simple of doing this.

DECLARE @listContactIdStr VARCHAR(MAX)
select  @listContactIdStr COALESCE(@listContactIdStr+',' ,'') +ContactId from dbo.ContactGroupReln where ContactGroupId=@ContactGroupId

SELECT 
@listContactIdStr

Please let me know, if it is not helping you.
0
Photo of Anurag Sarkar
NA 2.4k 308k 12y
Please check this link and try the query out there http://www.c-sharpcorner.com/UploadFile/ff2f08/comma-separated-value-in-sql-query/