• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Problem with date and time

U

Ukaygee

Guest
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:

jo-thijs

Member
the programme checks to see if that given date is 2 weeks ago or more
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
}
I just want to know how to convert any date into the second of the year that is.
date_get_second_of_year, but that won't be useful to you.
What about the time just after new year?
 
U

Ukaygee

Guest
@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?
 

jo-thijs

Member
@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?
You're right, that was silly of me.
 
Top