C LAB‎ > ‎

### Beyond

Programming Beyond College

#### Date - Time Operations. How long can you last?

posted Jan 22, 2011, 12:11 AM by Neil Mathew   [ updated Jan 22, 2011, 3:41 AM ]

Dad asked me to try a question yesterday. Let's see how far I can reach here.

Q.  WAP to accept the starting date and time and the ending date and time and find the total time in minutes that has transpired in between.

Once that is done, I'll have to continue with two conditions.
One, Sunday should not be counted. No hours or minutes belonging to Sunday.
Two, No time between 6pm and 10am should be counted either.

A.  Under way...

Before I can start, I need to learn the date time functions available for use in the C library. I've taken the help of cplusplus.com. It has provided me with the following:

#### Fact #1:

The <time.h> headerfile has a number of functions dealing with time.

time_t is the derived datatype used to create variables storing seconds in decimal form.
It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC

struct tm
The structure contains nine members of type int, which are (in any order):
 123456789 ``````int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst;``````

The meaning of each is:
MemberMeaningRange
tm_secseconds after the minute0-61*
tm_minminutes after the hour0-59
tm_hourhours since midnight0-23
tm_mdayday of the month1-31
tm_monmonths since January0-11
tm_yearyears since 1900
tm_wdaydays since Sunday0-6
tm_ydaydays since January 10-365
tm_isdstDaylight Saving Time flag

tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems.

### Functions > - Functions I need to learn.

Time manipulation
 clock Clock program (function)
 >difftime Return difference between two times using time_t arguments (function)
 >mktime Convert tm structure to time_t (function)
 time Get current time (function)

Conversion:
 >asctime Convert tm structure to string (function)
 >ctime Convert time_t value to string (function)
 gmtime Convert time_t to tm as UTC time (function)
 >localtime Convert time_t to tm as local time (function)
 strftime Format time to string (function)

#### Marksheet Transfer.

posted Jan 21, 2011, 11:39 PM by Neil Mathew   [ updated Jan 22, 2011, 12:09 AM ]

 The PDF which contains everyone's semester marks are pretty difficult to use. It would be easier if I could see it on a excel sheet instead. So I tell myself, why not copy it into excel. I do just that to find all those columns and rows stuffed into a single cell of my excel sheet. Apparently, when I copy the whole table into a notepad, all the column divisions turn into spaces. Therefore, I needed to replace them into TABs which can be recognized as column divisions in excel. However, using the Find & Replace option in notepad isn't enough since the column containing Name of Student and Father's name have individual parts of their names separated into different columns and misaligning the whole table. Hence, I made a software which can tell apart a name from the numbers and replace the proper spaces with TABs. The exe file should be placed in a folder with a notepad file already created under the name Raw.txt which contains the directly copied table without the headers ( AND the first character should be a newline and should have ] at the end, acting as the EOF character ). On processing that, it will create a notepad file called Done.txt which will contain what I can copy into an excel sheet without difficulty (fully aligned). I've attached the program source code and an example of the Raw File.Console OUTPUT: 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15         All Rows Modified.[ Used Devcpp  ]

1-2 of 2