tm_wday


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: tm_wday

  1. #1
    Join Date
    May 2004
    Posts
    242

    tm_wday

    Hello,

    I have :-

    ...

    char formattedDate[13]="";

    time_t tim = time(NULL);
    tm *now = localtime(&tim);

    sprintf(formattedDate, "%02d/%02d/%d", now->tm_mday, now->tm_mon+1, now->tm_year+1900);

    and I'm trying to retrieve the day of the week, i.e. tm_wday

    I've tried doing:
    ...
    char currentDay[5]="";
    sprintf(currentDay, "%s", now->tm_wday);
    ...
    But this results in a core dump.

    Can someone please help ?

    Thanks,

    Imanuel.

  2. #2
    Join Date
    May 2006
    Posts
    176
    The tm_wday seems to contain the ordinal number of the week day (0-6). If you need the short name of the day, you could consider this:

    Code:
    static const char * names[7] = 
    {
        "Sun",
        "Mon",
        "Tue",
        "Wed",
        "Thu",
        "Fri",
        "Sat",
    };
    
    const char * name = names[now->tm_wday].
    I hope this makes sense.

  3. #3
    Join Date
    Jan 2007
    Posts
    145
    Check data type of now->tm_wday

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    In addition to what others have proposed, you should replace the following statement:
    tm *now = localtime(&tim);
    with:
    tm now = *localtime(&tim);

    And then use the dot notation to access members of now. This will not fix your bug but it will fix other bugs that you may haven't noticed.
    Danny Kalev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center