-
July 8th, 2012, 04:20 PM
#1
Comparing Time in C# and MySQL
Hello everyone
I'm writing something for fun using both C# and MySQL.
To make things short I want to check if a certain user registered more than 24 hours ago.
I have made a collumn in my table "users" called "timereg", indicating the time they registered. The values of the collumn are as follows:
Code:
`timereg` timestamp NOT NULL DEFAULT 'CURRENT_TIMESTAMP',
Now I want to create a function to compare the timestamp in the database and the current time (using DateTime)
here is my function
Code:
public static void check(string username)
{
Server.Database.RunQuery("SELECT `timereg` FROM users WHERE name = '" + username + "'");
MySqlDataReader data = Server.Database.Reader;
if (data.GetDateTime("timereg") > DateTime.Now.TimeOfDay)
{
//whatever here
}
else if (data.GetTimeSpan("timereg") < DateTime.Now.TimeOfDay)
{
//whatever here
}
data.Close();
}
Now, the problem is that I don't know how to compare the two. Could anyone help me with what function I should use to compare the two? In other words, instead of "data.GetTimeSpan", is there another function that I can use?
Thanks.
-
July 9th, 2012, 03:25 AM
#2
Re: Comparing Time in C# and MySQL
DateTime constructors include
DateTime(year, month, day, hour,minute,second,...);
Depends on the format of the mysql datetime you retrieve, parse it as another datetime then comparing it with DateTime.Now is also another option.
-
July 9th, 2012, 03:40 PM
#3
Re: Comparing Time in C# and MySQL
Originally Posted by thefollower
DateTime constructors include
DateTime(year, month, day, hour,minute,second,...);
Depends on the format of the mysql datetime you retrieve, parse it as another datetime then comparing it with DateTime.Now is also another option.
Thank you! I ended up comparing DateTime.Now and the date from the database (+24 hours)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|