1. Hey! Guest! The 31st GMC Jam will take place between Nov 16th, 12:00 UTC (Friday noon) and Nov 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Problem with date and time

Discussion in 'Programming' started by Ukaygee, Jun 12, 2018.

  1. Ukaygee

    Ukaygee Member

    Joined:
    Oct 28, 2017
    Posts:
    155
    Hey!

    So I'm trying to make a programme that, when given a date by a user, in the format DD/MM/YYYY, the programme checks to see if that given date is 2 weeks ago or more.

    To do this, I have got the current second of the year, which at the date of writing this is ~14,060,000, and I am trying to take 1209600 away from the current date, to find out what the second of the year was exactly two weeks ago, then comparing that with the inputted value, and then if the inputted value is less than the current second take away 1209600, then it is more than two weeks ago.

    The problem I have is that I don't know how to get the exact second of the year of a specified date.

    I tried this:
    Code:
    givendate = date_create_datetime(2016,5,29,0,0,0);
    
    Code:
    currentsecond = date-get_second_of_year(date_current_datetime());
    datesecond = date_get_second_of_year(givendate);
    if (datesecond < currentsecond - 1209600)
    {
        show_debug_message("It was longer than two weeks ago!");
    }
    **EDIT**
    I realise this may be a complicated explanation, essentially, I just want to know how to convert any date into the second of the year that is.

    Or, if that's not possible, I just want to know how to compare a given date to the current date and see if its more than two weeks ago.

    * * * *

    Anyone have any ideas?
     
    Last edited: Jun 12, 2018
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,671
    Code:
    var input_date = ...;
    var now = date_current_datetime();
    var threshold = date_inc_week(now, -2);
    
    if date_compare_date(input_date, now) <= 0 {
        // it's 2 weeks ago or more
    }
    date_get_second_of_year, but that won't be useful to you.
    What about the time just after new year?
     
  3. Ukaygee

    Ukaygee Member

    Joined:
    Oct 28, 2017
    Posts:
    155
    @jo-thijs Thank you! Using the second of the year was very stupid! I forgot new years existed for a moment there xD

    In your example, in the part where you are comparing the two dates, I thought you should compare input_date with the threshold?
     
  4. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,671
    You're right, that was silly of me.
     
  5. Ukaygee

    Ukaygee Member

    Joined:
    Oct 28, 2017
    Posts:
    155
    Ok, thank you so much!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice