Thread: Advise for Date and Time C Programing or Is there one around somewhere

  1. #1
    Registered User
    Join Date
    May 2014
    Posts
    2

    Advise for Date and Time C Programing or Is there one around somewhere

    Hi,


    I need some feedback/advise on how 'easy' or difficult is it to write this program or maybe anyone know of good example date program that I can start with.


    I need a datetime program that I can use that will accept date arguments in some datetime format and perform arithmetic on them. Example of what I am wanting to do as below, for example if the program is named mydatetime, sample run can be as follows:


    mydatetime 25-OCT-2014 20-OCT-2014
    - should print out the difference between the two in hours and minutes, sec


    mydatetime 25-OCT-2014 -2
    - should printout the date and time 2 days back


    mydatetime 25-OCT-2014 2
    - should printout the datet and ime 2 days in the future


    mydatetime
    - should print out the current date and time.


    For simplicity, I did not include the time above but I would want to include the timestamp as well and then perform the arithmetic in the date and time format as well.


    Currently, I am using a shell script that connect to a database and do the date calculation there . I did not have to install the database, there just happen to have an Oracle/DB2/Sybase database on most of the script that I needed to do date calculation on. I know need to do the same on a server where there is no database on.


    I can't use a Perl one since our SA don't want to install the additional modules that I need to use for some examples that I found so I am stucked with maybe writing my own C program which I know nothing about.


    In 'simple' terms, I need to have the program to do as below:
    - 01 - Check for command line argument, if nothing print current date
    - 02 - Check for command line argument that they are in the date format that the program expects and then do perform the date arithmetic giving the result in date or in number of days/hours-min-sec


    Any advice much appreciated. Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Look into "time.h". You'll have to do some parsing of the command line arguments to extract the data into the format you'll need.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ date time
    By rahulsk1947 in forum C++ Programming
    Replies: 2
    Last Post: 05-22-2007, 02:06 PM
  2. Date & Time
    By g4j31a5 in forum C++ Programming
    Replies: 10
    Last Post: 08-15-2006, 09:25 AM
  3. Date and Time
    By Calavera in forum C Programming
    Replies: 3
    Last Post: 11-26-2004, 03:56 PM
  4. Getting time and date
    By winsonlee in forum C++ Programming
    Replies: 3
    Last Post: 08-18-2004, 11:31 PM
  5. Date and Time
    By fkheng in forum C Programming
    Replies: 19
    Last Post: 06-10-2003, 02:51 AM