ID:140504
 
Code:
var/date=copytext(FX,findtext(FX,"/")+1) // Reads the "/" from the txt in the website.

if(date >= time2text(world.realtime,"MM-DD-YY")) // Checks if the date is from the txt is over or equal to my computers date.


Problem description:
I have a subscription system through my website and it ain't working properly with the dates.

txt file from the website:
gizhy/12-12-99

world.realtime:
12-14-09

It says I'm not a subscriber in which I am...

Can someone help me with this error, if more information is needed please tell me.

PS: Going to switch it to a web server to get dates to stop free subscription.
Gizhy wrote:
if(date >= time2text(world.realtime,"MM-DD-YY"))


Are you aware that both your date variable and the return value of time2text are text strings and thus you're basically calling SortText on them?

I'm not exactly sure what you wanted the check to do, so I can't really tell if this is anywhere close to what you had in mind.
In response to Schnitzelnagler
Oh sorry for the lack of info..

I'll explain it better.
if(date >= time2text(world.realtime,"MM-DD-YY"))


Is suppose to check if the date in the .txt file on my website which has "gizhy/12-12-99" in it's contents to see if my subscription expired or by checking your computers date, but it doesn't read through the whole date meaning that the "12-12-99" in the txt file is read wrong. Let me know if you need anymore more information.
In response to Gizhy
I'm sorry, but I fear I haven't really understood you, or more precisely the 'it doesn't read through the whole date' part.

Could you provide the following output:
world << "[FX]"
world << "[date]"
world << "[time2text(world.realtime,"MM-DD-YY")]"

And state what you'd want the if statement to return (should it be true, or false with the given output).

Thank you in advance.
In response to Schnitzelnagler
N/A
In response to Gizhy
Which is not what I asked.
I wanted to see debugging information...


Could you provide the following output (the actual values at runtime of your program for a given example):
world << "[FX]"
world << "[date]"
world << "[time2text(world.realtime,"MM-DD-YY")]"

And state what you'd want the if statement to return (should it be true, or false with the given output).
In response to Schnitzelnagler
Oh, sorry thought the coding would help ya.

FX: gizhy/12-12-99
Date: 12-12-99
world.timeofday: 12-14-09

I wanted the if statement to come out true so I have subcription.
In response to Gizhy
if("12-12-99" >= "12-14-09") evaluates to false, because, as I've mentioned, this calls SortText, which is clearly stated in the reference and explained.

As I tried to hint at, string comparison is not what you're looking for (and actually even a bad design decision).
In response to Schnitzelnagler
So what should I use instead of comparing the string? That's my problem.. Thanks for all the help also.
In response to Gizhy
Store the raw time rather than after you have formatted it with time2text. Use time2text for when you need to show the user what the date is in a readable format.
In response to Xioden
Ahh, I see now.. Feel pretty stupid...

Thanks a lot to the both of you's.
In response to Xioden
Yeah, I tried that, and when I check is the date of my subscription is over or equal to the date on my computer it would still mess up, say someone subscribed in December 24, 2009 for one month then it would be, January 24, 2010 as the expiration. So the "date" variable would be 12409 and the realtime would be 122409, and checking to see if date is bigger then realtime would fail... Is there any simple fix to this error? Thanks.
In response to Gizhy
Parse the text string and turn it into a realtime value. Assuming it's in MM/DD/YY format:

var/expdate = whatever

//text2num will stop on the "/" character
var/expmonth = text2num(expdate)
expdate = copytext(expdate, findtext(expdate, "/")+1)
var/expday = text2num(expdate)
expdate = copytext(expdate, findtext(expdate, "/")+1)
var/expyear = text2num(expdate)

var/exptime = expyear * 10000 + expmonth * 100 + expday

var/time = text2num(time2text(world.realtime, "YYMMDD"))

if(time > exptime)
//expired


Change the "YYMMDD" to "YYYYMMDD" if you have the date in MM/DD/YYYY format. And you can simplify things further if you just store it in YYYYMMDD format in the first place.

The trick here is that the first two (or four) digits are the year, the next two are the month, and the last two are the day, so you can just directly compare these values numerically.
In response to Garthor
Ok, let me try to get this straight.

If I stored the expiration date as YYYY/MM/DD format in the txt file it would read that seperatly and check if the date is larger then the world.realtime?
In response to Gizhy
No. If you stored the expiration date as YYYYMMDD in the text file, you could just directly convert that to a number, and compare it to text2num(time2text(world.realtime, "YYYYMMDD")).

Otherwise, you need to rearrange it so that it's in YYYYMMDD format.
In response to Garthor
I'd rather not give my code to other's. Sorry.
In response to Gizhy
time2text() is producing 12-18-2009 as output. text2num() isn't seeing past the - because it isn't meant to. If you leave out the - characters from time2text() you'll get the result you want.

Lummox JR
In response to Lummox JR
Sorry but the part that ain't working is the output. It's suppose to output: MM:12 DD:30 YYYY:9999, because on the txt file in my website it says gizhy/99991230 and I can't seem to get it to read that and compare it to the world.realtime and see if the expiration date on the txt file is still above the world.realtime.

                    src << "Todays Date:</B> [time2text(world.realtime,"MMDDYYYY")]"
src << "Subscription Expires:</B> [time2text(ExpirationTime,"MMDDYYYY")]"

//Which Output's:

//You're a Gizhy.Com Subscriber!
//Todays Date: 12182009
//Subscription Expires: 12182009


Sorry for bugging you all with this, it's just irritating me.
I'm not going to bother with "proper" design issues as those seem to not be so easily understood here. If you arrange your dates to YYYY-MM-DD or just YYYYMMDD, it'll work properly---even with the string sorting method.

Quick summary is that the text file should say this:
gizhy/19991212

And your comparison should look like this:
if(date >= time2text(world.realtime, "YYYYMMDD"))


You could also do it like so:
gizhy/1999-12-12
if(date >= time2text(world.realtime, "YYYY-MM-DD"))


The key issue is that you put the numbers in the correct order, and you'll want the full YYYY year and not the YY year---or else 1999's "99" value would be higher than 2009's "09" value.

I'm also not sure if your conditional is right. You are checking if the date in the text file is after the current date, in case you meant to be checking if the date is before the current date.
In response to Gizhy
Thank you everyone, I've figured it out.