Tuesday, November 1, 2011

Convert DATETIME TO TIMESPAN IN C#

In the previous post, I mentioned how to convert DATETIME to TIMESPAN.

Now if the requirement is to convert DATETIME TO TIMESPAN, we can do that in one line:

DateTime dt="XXX";
TimeSpan TS = new TimeSpan(dt.Now.Ticks);

This will convert the DateTime to TimeSPan.

Varun

53 comments:

Tom Santos said...

Extrapolating from the above suggestion, wouldn't this work:

Dim dtStartTime as new DateTime
Dim tsStartTime As TimeSpan = New TimeSpan(dtStartTime.Hour, dtStartTime.Minute, dtStartTime.Second)

Since TimeSpan takes hours, minutes, and seconds as arguments.

Web Development Company Chennai said...

Nice blog.. Thanks for sharing this blog information with us…

Anonymous said...

This does not work. Now is not a valid property on an instance of a DateTime.

Fawad Tariq said...
This comment has been removed by a blog administrator.
Anonymous said...

Totally nonsense! This converts apples to potatoes.
TimeSpan and DateTime are there because a date is a completely different thing than a time span: What date should "one week and five hours" be???

Albert Andrada said...

Really Nice Information,Thank You Very Much For Sharing.
Web Development Company

Sathya G said...

thank you for sharing such a nice and interesting blog with us. hope it might be much useful for us. keep on updating...
SEO Company In Chennai

Iqbal Dlk said...

very nice and informative blog
big data projects chennai
mobile computing projects chennai
cloud computing projects chennai
secure computing projects chennai

1croreprojects said...

Thanks for sharing this valuable information.
dotnet projects in chennai

vinu priya said...

This was so useful and informative. The article helped me to learn something new. Android App Development Company in Chennai

Mahalyasree said...

This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.Your final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.
Architectural Firms in Chennai
Architects in Chennai

Abiya Carol said...

It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..

Dot Net Training in Chennai

Software Testing Training in Chennai

Amelia Lily said...

I do trust all of the concepts you’ve presented on your post. They’re really convincing and will definitely work. Still, the posts are too brief for newbies. May you please extend them a little from subsequent time?Also, I’ve shared your website in my social networks.
Best Architects in Chennai
Turnkey Interior Contractors in Chennai
Interior Contractors in Chennai
Architecture Firms in Chennai
Best Interior Designers in Chennai

Ancy merina said...
This comment has been removed by the author.
Atom Steels said...

Fertility is the natural capability to produce offspring. As a measure, fertility rate is the number of offspring born per mating pair, individual or population.Human fertility depends on factors of nutrition, sexual behavior, consanguinity, culture, instinct, endocrinology, timing, economics, way of life, and emotions.Greate thinks of a fertility center for humans.

Fertility Center in OMR

Arushi Chaya said...

I have really happy to these reading your post. This product control and maintenance of our health.The daily routine can assist you weight lose quickly and safely.My life is completely reworked once I followed this diet.I feeling nice concerning myself.

Herbalife in Chennai
Herbalife Nutrition Products
Nutrition centers in Chennai
Weight Loss in Chennai
Weight Gain in Chennai

sujitha s said...


BIG DATA Technologies provides you with a state of the art software which combines modern GPU technology (Graphic Processing Units) with the best practices in today’s Big Data platforms, providing up to 100x faster insights from data.
Bigdata Training in Chennai OMR

Shivani Yuvanjalin said...

This post is worth for me. Thank you for sharing.
ERP in Chennai
ERP Software in Chennai
SAP Business One in Chennai
SAP Hana in Chennai
SAP r3 in Chennai

john brito said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
best rpa training in bangalore
rpa training in bangalore | rpa course in bangalore
RPA training in bangalore
rpa training in chennai
rpa online training

john brito said...
This comment has been removed by the author.
saranyaregan said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
best rpa training in bangalore
rpa training in bangalore | rpa course in bangalore
RPA training in bangalore
rpa training in chennai
rpa online training

tamilsasi said...

I was recommended this web site by means of my cousin.
I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!

Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

manisha said...

Thanks for sharing your post really it was a greatly helped to my future.
apple service center chennai | Mac service center in chennai | ipod service center in chennai | Apple laptop service center in chennai

Yogayogi said...

Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
python training Course in chennai
python training in Bangalore
Python training institute in bangalore

Yogayogi said...

I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.
python training Course in chennai
python training in Bangalore
Python training institute in bangalore

noor noor said...

شركة مكافحة حشرات بالنعيرية

jefrin adams said...

Best blog thanks for sharing
Best blue prism training in chennai

sarah blossom1234567 said...

Really you have done great job,There are may person searching about that now they will find enough resources by your post
AWS Training in Bangalore

AWS Training in pune

sarah blossom1234567 said...

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
AWS Training in Bangalore

AWS Training in pune

رجب البرنس said...


بسم الله الرحمن الرحيم نحن فى شركة الكمال نقوم بجميع عزل الخزانات المياه سواء كانت مياة الشرب او

مياه الغسيل كما اننا يوجد لدين خدمة تسليك المجارى بافضل الطرق
شركة عزل خزانات بالطائف
شركة عزل خزانات بجازان
شركة عزل خزانات بحائل
والسلامة عليكم ورحمة الله وبركاته

Ananya M said...
This comment has been removed by the author.
shiny said...

Wow..U have given a great solution in simple format.i keep following ur blogs.quite interesting.keep blogging with new new solutions.all the best.
lenovo service center
lenovo mobile service center near me
lenovo mobile service centre in chennai
lenovo service center in velachery

Ramya Krishnan said...

This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information regarding Microsoft Azure which is latest and newest,

Regards,
Ramya

Azure Training in Chennai
Azure Training Center in Chennai
Best Azure Training in Chennai
Azure Devops Training in Chenna
Azure Training Institute in Chennai
Azure Training in Chennai OMR
Azure Training in Chennai Velachery
Azure Online Training

IT Tutorials said...

Really useful information. Thank you so much for sharing.It will help everyone.Keep Post. RPA training in chennai | RPA training in Chennai with placement | UiPath training in Chennai | UiPath certification in Chennai with cost

yashnit said...

Thanks For sharing the Information The Information Shared Is Very valuable please Keep Updating Us The InFormation Shared Is Very Valuable Python Online Training Hadoop Online Training <a href="https://nareshit.com/data-science-online-training/>DataScience Online Training</a>

IT Tutorials said...

Really useful information. Thank you so much for sharing.It will help everyone.Keep Post. RPA training in chennai | RPA training in Chennai with placement | UiPath training in Chennai | UiPath certification in Chennai with cost

franklinraj said...

Thank you for excellent article.

Please refer below if you are looking for best project center in coimbatore

soft skill training in coimbatore
final year projects in coimbatore
Spoken English Training in coimbatore
final year projects for CSE in coimbatore
final year projects for IT in coimbatore
final year projects for ECE in coimbatore
final year projects for EEE in coimbatore
final year projects for Mechanical in coimbatore
final year projects for Instrumentation in coimbatore

Ramya Krishnan said...

This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information regarding Microsoft Azure which is latest and newest,

Regards,
Ramya

Azure Training in Chennai
Azure Training Center in Chennai
Best Azure Training in Chennai
Azure Devops Training in Chenna
Azure Training Institute in Chennai
Azure Training in Chennai OMR
Azure Training in Chennai Velachery
Azure Online Training
Azure Training in Chennai Credo Systemz
DevOps Training in Chennai Credo Systemz

IT Tutorials said...

Really useful information. Thank you so much for sharing.It will help everyone.Keep Post. RPA training in chennai | RPA training in Chennai with placement | UiPath training in Chennai | UiPath certification in Chennai with cost

Sadhana Rathore said...

This is a very interesting post and I learned so much from your blog. Do posting more.
AWS Training in Chennai
AWS course in Chennai
Cloud Computing Courses in Chennai
Cloud Computing Training in Velachery
Azure Training in Chennai
Azure Training center in Chennai
DevOps Certification in Chennai
AWS Training in Chennai
AWS course in Chennai

Chiến SEOCAM said...

Sehr ausgezeichnet, ein hervorragender Artikel. Danke

chó Bull Pháp

bán chó bull pháp

chó bull pháp giá bao nhiêu

mua chó bull pháp

Durai Raj said...

Great information!!! The way of conveying is good enough… Thanks for it
PHP Training in Coimbatore
best php training institute in coimbatore
php training institute in coimbatore
Devops Training in Bangalore
Digital Marketing Courses in Bangalore
German Language Course in Madurai
Cloud Computing Courses in Coimbatore

Shadeep Shree said...

Outstanding blog!!! Thanks for sharing with us...
IELTS Coaching in Coimbatore
Best IELTS coaching center in coimbatore
IELTS Training Coimbatore
Software Testing Course in Coimbatore
Spoken English Class in Coimbatore
Web Designing Course in Coimbatore
Tally Course in Coimbatore

Chiến SEOCAM said...

Chúc bạn luôn hạnh phúc và may mắn. Hy vọng bạn sẽ có nhiều bài viết hay hơn.

giảo cổ lam giảm cân

giảo cổ lam giảm béo

giảo cổ lam giá bao nhiêu

giảo cổ lam ở đâu tốt nhất

jvimala said...


Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.

blockchain training in chennai | best blockchain training in chennai | blockchain coaching in chennai

al ghadeer said...

شركة عزل فوم بالرياض
شركة عزل فوم بالخرج
شركة عزل فوم بالمزاحمية
شركة عزل فوم بالقويعية
شركة عزل فوم بالدوادمى
شركة عزل فوم بالمجمعة

wemake said...

Download latest audio and video file fromvidmate

Benish said...

Nice post.. thank you for sharing useful information..
Best Python Training in Chennai/Python Training Institutes in Chennai/Python/Python Certification in Chennai/Best IT Courses in Chennai/python course duration and fee/python classroom training/python training in chennai chennai, tamil nadu/python training institute in chennai chennai, India/

shivam said...

Flying Shift - Packers & Movers in Bhopal

tech updates said...

nice blog
DATA SCIENCE TRAINING IN BANGALORE"
MACHINE LEARNING TRAINING IN BANGALORE
BIG DATA AND HADOOP TRAINING IN BANGALORE

lajwantidevi said...

vidmate app

Kasaikannu Catering said...

Best Catering Services in Chennai | Best Catering Service in Chennai | Best Catering Services Chennai | Best Catering Service Chennai | Best Catering Services | Best Catering Service

gokul said...

Thanks for this informative blog
Top 5 Data science training in chennai
Data science training in chennai
Data science training in velachery
Data science training in OMR
Best Data science training in chennai
Data science training course content
Data science certification in chennai
Data science courses in chennai
Data science training institute in chennai
Data science online course
Data science with python training in chennai
Data science with R training in chennai