Author Topic: OT - MySQL Question(s)  (Read 1933 times)

jemagee

  • Guest
OT - MySQL Question(s)
« on: November 20, 2008, 12:19:05 PM »
Ok - so I have a MySQL question after I spent an hour yesterday dealing with 'start times' for games.

I thought it would be easy to compare real times and it turns out it isn't. 

In my 'games' table I have a game date field and a game time field - what's the best way to take these two fields, combine them, and create the datetimestamp from them?  Is there a simple way using a sql query?

Offline westkoast

  • Hero Member
  • *****
  • Posts: 8624
    • View Profile
    • Email
Re: OT - MySQL Question(s)
« Reply #1 on: November 20, 2008, 12:39:39 PM »
You want to combine both of them into another field?

If you are trying to display a time stamp on a web page it's pretty basic, at least in php, you place the results of the query into a variable and echo it out.
http://I-Really-Shouldn't-Put-A-Link-To-A-Blog-I-Dont-Even-Update.com

jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #2 on: November 20, 2008, 12:41:55 PM »
I want to combine them into another field.

The way I have it set up now i have to get the time convert it to a time stamp and then see if the current time (+20 minutes) stamp is more or less than the time stamp on the start time of the first game - thus determining if picks can be made or not.  I sort of worked it backwards cause I didn't think it through.  I'd just like the start time to be a datetimestamp so i can compare more easily - plus i'm concerned that by only comparing times (converted into time stamp) someone can get around my function in the 11:40 to midnight time window.

I'm not even sure it's a problem until i test it but if i change the table set up so the start time is already the date/time stamp it becomes an easier functionality (i think)

Offline Derek Bodner

  • Administrator
  • Hero Member
  • *****
  • Posts: 3040
    • AOL Instant Messenger - dbodner22
    • Yahoo Instant Messenger - dabodz
    • View Profile
    • http://www.phillyarena.com
    • Email
Re: OT - MySQL Question(s)
« Reply #3 on: November 20, 2008, 12:56:15 PM »
What's the reasoning for having it separated to begin with?  From a data integrity standpoint, that's not really the way to go.

Offline WayOutWest

  • Hero Member
  • *****
  • Posts: 7411
    • View Profile
Re: OT - MySQL Question(s)
« Reply #4 on: November 20, 2008, 01:02:22 PM »
Are you using a programming laguage or strictly SQL?

If it's just SQL just convert the date and time to seconds or milliseconds and compare the two.
"History shouldn't be a mystery"
"Our story is real history"
"Not his story"

"My people's culture was strong, it was pure"
"And if not for that white greed"
"It would've endured"

"Laker hate causes blindness"

jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #5 on: November 20, 2008, 01:02:33 PM »
Like I said in the post you replied to - I didn't think it through (properly) when I was planning it.  It's the first site I've ever built and have limited experience working with these things from scratch, I'm used to working with databases already built, or filemaker pro which is an entirely different kind of animal until its most recent versions.

jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #6 on: November 20, 2008, 01:03:29 PM »
Are you using a programming laguage or strictly SQL?

If it's just SQL just convert the date and time to seconds or milliseconds and compare the two.

I'm using PHP with MySQL

The start date and time are currently separate fields...i can combine them using the PHP i just thought having them combined and 'time stamped' already in the database would make it run more efficientliy as I'd just have to get the field and compare it to the server timestamp without having to manipulate either.

Offline WayOutWest

  • Hero Member
  • *****
  • Posts: 7411
    • View Profile
Re: OT - MySQL Question(s)
« Reply #7 on: November 20, 2008, 01:05:40 PM »
Are you using a programming laguage or strictly SQL?

If it's just SQL just convert the date and time to seconds or milliseconds and compare the two.

I'm using PHP with MySQL

The start date and time are currently separate fields...i can combine them using the PHP i just thought having them combined and 'time stamped' already in the database would make it run more efficientliy as I'd just have to get the field and compare it to the server timestamp without having to manipulate either.

Convert both fields to seconds/milliseconds
Add the two
Reformat the result back into a date/time format.
"History shouldn't be a mystery"
"Our story is real history"
"Not his story"

"My people's culture was strong, it was pure"
"And if not for that white greed"
"It would've endured"

"Laker hate causes blindness"

jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #8 on: November 20, 2008, 01:09:18 PM »
Quote
Convert both fields to seconds/milliseconds
Add the two
Reformat the result back into a date/time format.

I'll have to look into that...thanks for your help.  i just worried that by using 'only the time' as my comparing factor that the midnight issue might screw things up...btw - if you're curios

Here's where it's at now - the submit won't work - but i'm hoping to get something functional sooner than later

http://student49.tangostudents.com/Interface%20Design/picks.php




jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #9 on: November 20, 2008, 01:15:41 PM »
BTW - are people still terrified of cookies on web sites?

Offline Lurker

  • Hero Member
  • *****
  • Posts: 3705
    • View Profile
    • Email
Re: OT - MySQL Question(s)
« Reply #10 on: November 20, 2008, 01:36:14 PM »
BTW - are people still terrified of cookies on web sites?

Only the ones with nuts in them.

 ;)
It riles them to believe that you perceive the web they weave.  Keep on thinking free.
-Moody Blues

jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #11 on: November 20, 2008, 04:13:58 PM »
WOW

Thanks for your suggestions, i used a modification that your suggestion spurred in my php code - got the date as one variable - time as another - merged them and then strtotime

It works and my worries on the close to midnight thing are taken care of...course now i realized i have to do this check twice - when they try to make picks and when they try to submit - but at least now i have something i have confidence in.


Offline WayOutWest

  • Hero Member
  • *****
  • Posts: 7411
    • View Profile
Re: OT - MySQL Question(s)
« Reply #12 on: November 20, 2008, 04:20:24 PM »
WOW

Thanks for your suggestions, i used a modification that your suggestion spurred in my php code - got the date as one variable - time as another - merged them and then strtotime

It works and my worries on the close to midnight thing are taken care of...course now i realized i have to do this check twice - when they try to make picks and when they try to submit - but at least now i have something i have confidence in.



No problem.  Your crumbling down the stretch of our week 2 matchup is thanks enough.  ;D
"History shouldn't be a mystery"
"Our story is real history"
"Not his story"

"My people's culture was strong, it was pure"
"And if not for that white greed"
"It would've endured"

"Laker hate causes blindness"

jemagee

  • Guest
Re: OT - MySQL Question(s)
« Reply #13 on: November 20, 2008, 04:34:30 PM »
Quote
No problem.  Your crumbling down the stretch of our week 2 matchup is thanks enough.

My team is not good :) I did warn you all i wasn't very good at this - seriously - i should just concede turnovers every week - every season - i tend to pick the turnover prone players - and i expect not playing mobley and kaman last night (instead of chander and durant) will cost me even though i'm now up 10-1 - weekends always kill me :)

Offline Derek Bodner

  • Administrator
  • Hero Member
  • *****
  • Posts: 3040
    • AOL Instant Messenger - dbodner22
    • Yahoo Instant Messenger - dabodz
    • View Profile
    • http://www.phillyarena.com
    • Email
Re: OT - MySQL Question(s)
« Reply #14 on: November 20, 2008, 04:48:31 PM »
Quote
It works and my worries on the close to midnight thing are taken care of...course now i realized i have to do this check twice - when they try to make picks and when they try to submit - but at least now i have something i have confidence in.

Create a php function, pass the date and time, return the stamp.

Or, better yet, mysql function/stored procedure.