checking a mysql timestamp

Discussion in 'Plugin Development' started by jwnordquist, Apr 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    jwnordquist

    Hey, new to java, so my friend was helping me out with this plugin, however we cant seem to figure out how to check the timestamp for weather or not they have voted in the past 24 hours. if anyone could help me out that would be great!

    thanks, jake

    Code:
            try {
                rs = st.executeQuery("SELECT timestamp FROM votes WHERE minecraft_user='"+username+"'");
                rs.next();
                has_voted = rs.getString(1);
                if (**need code to check timestamp**)
                {
                    
                }
                else
                {
    
                }
    
     
  2. Offline

    Sessional

    What is the format of your timestamp field in the database? Seems like it'd be largely dependent upon how you stored the time they last voted.
     
  3. Offline

    jwnordquist

    right now im just using the time stamp mysql puts in there, however im willing to switch it if i need to.

    EDIT: this is how the timestamp looks like: 2012-03-16 00:11:48
     
  4. Offline

    Sessional

    What format is that?
    YYYY-MM-DD HH:MM:SS
    I seem to have found this somewhere, is that the format your database sticks in there? I don't use MYSQL so I don't know.
    Also, are you doing this in java?
     
  5. Offline

    jwnordquist

    yeah that is the way its put in there
    and java is not puting the timestamp in there, mysql will auto put it in, and update it every time you edit that table.
     
  6. Offline

    Sessional

    Using String.split(" ") and String.split("-") etc you can break that timestamp down into workable units.
    Code:
    if (day is not last day in month)
       if currentDay - timeStampDay > 1
          if currentHour - timeStampHour >= 0
             if currentMinute - timeStampMinute >= 0
                 if currentSecond - timeStampSecond >= 0
                      do allow vote
    
    If you do a timestamp.Split(" ") you'll get an array of the contents:
    {"YYYY-MM-DD", "HH:MM:SS"} by executing a split on each of those indices for their respective dividers you can break it down into the individual parts you need. Then just use Integer.parseInt(String) to get it into int format so you can apply math operations on it.
     
  7. Offline

    jwnordquist

    Ok thanks, ill try it out.
     
Thread Status:
Not open for further replies.

Share This Page