Results 1 to 5 of 5

Thread: Get the date from day of year and year details

  1. #1
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Get the date from day of year and year details

    Hi,

    This might be easy, but I couldn't find a solution.

    If I have the day of year example 365 and the year 2013. Is it possible to convert it to date format 31.12.2013 in Qt? I didn't find anything for conversion from day of year. I tried using

    QDate date_test = QDate::fromString("2014365","yyyyddd"); But it is invalid as the documents say ddd format means abbreviated localized day name (e.g. 'Mon' to 'Sun'). Is there any other way I can go about it in Qt?

    Thank you in advance.

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Get the date from day of year and year details

    Use Julian period. First construct a QDate for 01.01.year, then convert to Julian date, then add DayInTheYear - 1, then convert back to "normal" date.

  3. #3
    Join Date
    Aug 2013
    Posts
    25
    Thanks
    7
    Qt products
    Qt5

    Default Re: Get the date from day of year and year details

    Hi,

    Oh, I had done the same. Was looking for qt functions rather than this work around. Since we can get day of year from qdate I assumed there maybe a way to do the opposite. Thanks anyway

    Just adding the work around I had done earlier to convert day of year, year to qdate
    day_of_year = 365;
    year = 2013;
    QString test_date = QString::number(year);
    test_date.append("0101");
    QDate date = QDate::fromString(test_date,"yyyyMMdd");
    date = date.addDays(day_of_year-1);
    Last edited by gfernandes; 16th May 2014 at 14:37.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get the date from day of year and year details


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Get the date from day of year and year details

    Specifically,
    Qt Code:
    1. QDate date = QDate(year, 1, 1).addDays(dayOfYear - 1);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Happy New Year!
    By Awareness in forum General Discussion
    Replies: 0
    Last Post: 1st January 2014, 15:57
  2. Happy New Year!!!
    By fengtian.we in forum General Discussion
    Replies: 6
    Last Post: 4th January 2012, 06:07
  3. QDate and two digit year
    By Lesiok in forum Qt Programming
    Replies: 8
    Last Post: 24th March 2011, 09:13
  4. hello. happy new year
    By Andrewliu in forum General Discussion
    Replies: 4
    Last Post: 30th December 2006, 19:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.