1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help to convert date to double

Discussion in 'C' started by Musab, Jul 1, 2008.

  1. Musab

    Musab New Member

    Joined:
    Jul 1, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    here is the code

    -----------------------------

    char * date;

    time_t timer;
    timer = time(NULL);
    date = asctime(localtime(&timer));

    printf("Current Date: %s", date);


    getchar();
    return 0;

    ------------------------------

    I'm trying to print a double number to generate a unique key

    thank you
     
  2. dssr

    dssr New Member

    Joined:
    Feb 16, 2008
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programming
    Location:
    Kolkata
    could not get you can you be a little bit more specific?
     
  3. Musab

    Musab New Member

    Joined:
    Jul 1, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Sure! If you look at the code, it prints the date as a string, for example the result will be

    Fri July 04 2008 12:00 p.m.

    I want to print this instead: 07042008

    or 070420081200

    or convert the sting "Fri July 04 2008 12:00p.m." to double

    I tried atof() but gives me 0.000

    thank you

     
  4. dssr

    dssr New Member

    Joined:
    Feb 16, 2008
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programming
    Location:
    Kolkata
    you can do that by using _strdate function
    Code:
    #include<stdio.h>
    #include<time.h>
    
    int main(void)
    {
    	char datebuf[9];
    	_strdate(datebuf);
    	printf("Date : %s",datebuf);
    	return 0;
    }
    similarly you may use _strtime for time and if you want to make a program where you enter the date in the format you specified you may convert that string to the output you want without using any function,if you want that please reply here
     
  5. dssr

    dssr New Member

    Joined:
    Feb 16, 2008
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programming
    Location:
    Kolkata
    and i have posted an article on date and time management functions of C, please visit that, that may help you
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
  7. Musab

    Musab New Member

    Joined:
    Jul 1, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Thank you so much guys ! I was using CVI which got its own time functions, but what you gave me helped.
     
  8. dssr

    dssr New Member

    Joined:
    Feb 16, 2008
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programming
    Location:
    Kolkata

    My pleasure :pleased:
     

Share This Page