Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 28th, 2006, 10:37 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default DateTime Calculations

I have an ASP.NET form(using C#) with several text boxes and when the user places a date in the first textbox and clicks a button, I would like to populate the remaining textboxes with various dates subtracted from the date in the first textbox - any suggestions? I do know that the datetime class has a subtract method, but I'm not sure how to use it. Incidentally I'm using ASP.NET 2005 and obviously a beginner - please help!

Thanks,
Mike

Reply With Quote
  #2 (permalink)  
Old May 31st, 2006, 08:44 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike,

Here is some code that may help. Before it gets lost, I would like to pass a value to a function from a label to a function, but can't find the syntax. If you happen to know how to do that, I would appreciate the help.

Your code:


string strDate;

// Calculating the tomorrow's date (adding days to the current date.)
DateTime tomorrow = DateTime.Today.AddDays( 1 );
strDate = tomorrow.ToString("dd / MM / yy");

// Calculating the yesterday's date (substracting days from current date.)
DateTime yesterday = DateTime.Today.AddDays( -1 );
strDate = yesterday.ToString("dd / MM / yy");

// Calculating the time after 15 minute (adding minutes to the current
time.)
// Format : 09 / 08 / 06, 12 : 60
DateTime later = DateTime.Now.AddMinutes( 15 );
strDate = later.ToString("dd / MM / yy, hh : mm ");


// Calculating the time after 1 hour (adding minutes to the current
time.)
// Format : 09 / 08 / 06, 12 : 60
DateTime later = DateTime.Now.AddMinutes( 60 );
strDate = later.ToString("dd / MM / yy, hh : mm ");


// Calculating the time before 1 hour (adding minutes to the current
time.)
// Format : 09 / 08 / 06, 12 : 60
DateTime later = DateTime.Now.AddMinutes( -60 );
strDate = later.ToString("dd / MM / yy, hh : mm ");

OldCoder



Reply With Quote
  #3 (permalink)  
Old June 1st, 2006, 10:00 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why the formatting of "MM" is different from "yy" or "dd"? Anyone can tell me the reason?

Thanks,
MagicXY

Reply With Quote
  #4 (permalink)  
Old June 1st, 2006, 01:33 PM
Authorized User
 
Join Date: Feb 2006
Location: Bluefields, , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default

The main reason for that is because DateTime dataType can have time format also, wich means HH:mm:ss (Hours:minutes:seconds). Therefore, Months (MM) must have a different format than minutes (mm). Days and years are good in lowercase.

Greetings,



MAKO - "El super simio"
Reply With Quote
  #5 (permalink)  
Old June 2nd, 2006, 06:18 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your answering.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DatePart Calculations ninel SQL Language 2 February 29th, 2008 03:08 AM
DateTime calculations sudarshan73 SQL Language 8 April 7th, 2005 09:07 AM
UTC DateTime to Local DateTime r_ganesh76 SQL Server 2000 1 April 4th, 2005 08:21 AM
DateTime calculations sudarshan73 SQL Server 2000 1 March 15th, 2005 03:13 PM
calculations between records plenarts Access 5 December 30th, 2004 08:05 AM



All times are GMT -4. The time now is 03:35 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.