This is a discussion on getting the current date/time within the MySQL Database forums, part of the Database Forums category; > > $ perl -MTime::HiRes=gettimeofday -e '$time=gettimeofday();print "$time\n"' > 1171908671.04656 > That's ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
>
> $ perl -MTime::HiRes=gettimeofday -e '$time=gettimeofday();print "$time\n"' > 1171908671.04656 > That's all very well if I was writing a perl program and the machine is local, but I'm writing a Java program and the machines are remote. As I already have a JDBC connection to each machine I'm interested in, SQL is the easiest way for me to get the time on those machines. |
|
|||
|
donalmurtagh@yahoo.co.uk wrote:
>> $ perl -MTime::HiRes=gettimeofday -e '$time=gettimeofday();print "$time\n"' >> 1171908671.04656 >> > > That's all very well if I was writing a perl program and the machine > is local, but I'm writing a Java program and the machines are remote. > As I already have a JDBC connection to each machine I'm interested in, > SQL is the easiest way for me to get the time on those machines. > And definitely the wrong way. Since you're using Java, set up a jsp to return it, or have a java object to run on the machine - or any of several other ways of doing it. But MySQL won't give you the detail you need, and it's like using a hammer to drive in a screw. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Why use sarcasm to answer a question -- why not just say the result
would always be 0? And why use profanity? I observed this newsgroup was dead -- then realized it was a weekend. So I (being a novice) threw out an answer I thought might help. An observation is a complaint only to the tender skinned or guilty. On Feb 18, 4:14 pm, Rik <luiheidsgoe...@hotmail.com> wrote: > On Sun, 18 Feb 2007 19:59:16 +0100, <christop...@dailycrossword.com> wrote: > > On Feb 18, 10:17 am, Rik <luiheidsgoe...@hotmail.com> wrote: > >> On Sun, 18 Feb 2007 18:21:32 +0100, <christop...@dailycrossword.com> > >> wrote: > > >> > in MySQL there is a DATE_FORMAT function which allows you to specify > >> > the output of a date. > > >> But that still won't give you the _current_ microseconds... > > > DATE_FORMAT(date,format) > > ... > > %f Microseconds (000000..999999) > > > what do you mean by current? Oh, you are making a joke. Confusing, > > since I just spent 20 minutes trying to figure out what you said I was > > doing wrong. > > I'm not joking, the question was not to get the microsconds form _a_ date > (which is hidiously easy with date_format), but a timestamp _with_ the > microseconds of the exact time it's called: > > <donalmurt...@yahoo.co.uk> wrote: > > Is there any way that I can (with SQL) retrieve the current date/time > > that shows fractions of a second (milliseconds, microseconds, etc.). > > If I execute: > > > select now() > > > It returns the current date/time, but only to the nearest second. I > > would like to get a more precise measure of the current date/time and > > if I could get it in the following format, that would be even better: > > > yyyy-mm-dd hh:mm:ss.ffff > > DATE_FORMAT(NOW(),'%f') will always result in 000000 > > So, in short, before you complain about the quality of a newsgroup don't > talk out of your ass. > -- > Rik Wasmus |
|
|||
|
<christopher@dailycrossword.com> wrote:
> Rik <luiheidsgoe...@hotmail.com> wrote: >> >> > in MySQL there is a DATE_FORMAT function which allows you to >> specify >> >> > the output of a date. >> >> >> But that still won't give you the _current_ microseconds... >> >> > what do you mean by current? Oh, you are making a joke. Confusing, >> > since I just spent 20 minutes trying to figure out what you said I was >> > doing wrong. >> >> I'm not joking, the question was not to get the microsconds form _a_ >> date >> (which is hidiously easy with date_format), but a timestamp _with_ the >> microseconds of the exact time it's called: >> DATE_FORMAT(NOW(),'%f') will always result in 000000 >> So, in short, before you complain about the quality of a newsgroup don't >> talk out of your ass. >Why use sarcasm to answer a question -- why not just say the result > would always be 0? And why use profanity? I observed this newsgroup > was dead -- then realized it was a weekend. So I (being a novice) > threw out an answer I thought might help. > > An observation is a complaint only to the tender skinned or guilty. I'm sorry, a was a bit peeved by: a. A wrong answer. b. The fact that I told you it was a wrong answer was considered a joke. c. (mostly) about being declared dead. Observations are not always true, but forgive my rudeness. -- Rik Wasmus |
|
|||
|
>
> And definitely the wrong way. Since you're using Java, set up a jsp to > return it, or have a java object to run on the machine - or any of > several other ways of doing it. > > But MySQL won't give you the detail you need, and it's like using a > hammer to drive in a screw. > I agree that using SQL isn't necessarily the best way, but a JSP? You want me to run a webserver just so I can get the current time on a box? Maybe you assumed this is a web app, but it's not. I'm running a J2SE process on a box that needs to detect the time on other boxes. Ideally, I would use RMI, but that's *a lot* of overhead just to get the system time. |
|
|||
|
> Wouldn't it be FAR easier just to have the java apps open an independant > connection between themselves and use the java timestamp, which DOES go > to milliseconds, to detect if they're out of sync? > If there was already a Java process running on each box I'm interested in then I could use sockets or RMI to pass the timestamps around. However, the actual scenario is one java (J2SE) process running on a box which needs to get the time on other remote boxes. |
|
|||
|
donalmurtagh@yahoo.co.uk wrote:
>> And definitely the wrong way. Since you're using Java, set up a jsp to >> return it, or have a java object to run on the machine - or any of >> several other ways of doing it. >> >> But MySQL won't give you the detail you need, and it's like using a >> hammer to drive in a screw. >> > > I agree that using SQL isn't necessarily the best way, but a JSP? > You want me to run a webserver just so I can get the current time on a > box? > Maybe you assumed this is a web app, but it's not. I'm running a J2SE > process on a box that needs to detect the time on other boxes. > Ideally, I would use RMI, but that's *a lot* of overhead just to get > the system time. > Ok, so you're not using a webserver there. Fine. But you think RMI is more overhead than invoking a MySQL query? I doubt RMI for something this basic would be that much overhead. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
>
> Ok, so you're not using a webserver there. Fine. But you think RMI is > more overhead than invoking a MySQL query? I doubt RMI for something > this basic would be that much overhead. > In terms of runtime performance, probably not, but in terms of effort and architecture, introducing RMI into a system that doesn't already use it, just for the sake of getting the time seems like overkill. The reason I want to get the time via SQL is because I know there will already be a MySql server running on the machine(s) I'm interested in. |