Bluehost.com Web Hosting $6.95

getting the current date/time

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 02-19-2007
donalmurtagh@yahoo.co.uk
 
Posts: n/a
Default Re: getting the current date/time

>
> $ 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.

Reply With Quote
  #12 (permalink)  
Old 02-19-2007
Jerry Stuckle
 
Posts: n/a
Default Re: getting the current date/time

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
==================
Reply With Quote
  #13 (permalink)  
Old 02-20-2007
christopher@dailycrossword.com
 
Posts: n/a
Default Re: getting the current date/time

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



Reply With Quote
  #14 (permalink)  
Old 02-20-2007
Rik
 
Posts: n/a
Default Re: getting the current date/time

<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
Reply With Quote
  #15 (permalink)  
Old 02-20-2007
donalmurtagh@yahoo.co.uk
 
Posts: n/a
Default Re: getting the current date/time

>
> 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.

Reply With Quote
  #16 (permalink)  
Old 02-20-2007
donalmurtagh@yahoo.co.uk
 
Posts: n/a
Default Re: getting the current date/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.

Reply With Quote
  #17 (permalink)  
Old 02-20-2007
Jerry Stuckle
 
Posts: n/a
Default Re: getting the current date/time

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
==================
Reply With Quote
  #18 (permalink)  
Old 02-20-2007
donalmurtagh@yahoo.co.uk
 
Posts: n/a
Default Re: getting the current date/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.
>


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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0