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; Hi, Is there any way that I can (with SQL) retrieve the current date/time that shows fractions of a ...


Go Back   Usenet Forums > Database Forums > MySQL Database

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

Hi,

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

Thanks in advance,
TD

Reply With Quote
  #2 (permalink)  
Old 02-18-2007
christopher@dailycrossword.com
 
Posts: n/a
Default Re: getting the current date/time


in MySQL there is a DATE_FORMAT function which allows you to specify
the output of a date.

man this group is dead, is there a better group for these types of
questions?

-- clh


On Feb 17, 1:23 pm, donalmurt...@yahoo.co.uk wrote:
> Hi,
>
> 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
>
> Thanks in advance,
> TD



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

On Sun, 18 Feb 2007 18:21:32 +0100, <christopher@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...
--
Rik Wasmus
Reply With Quote
  #4 (permalink)  
Old 02-18-2007
christopher@dailycrossword.com
 
Posts: n/a
Default Re: getting the current date/time

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.

-- clh


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



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

On Sun, 18 Feb 2007 19:59:16 +0100, <christopher@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:

<donalmurtagh@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
  #6 (permalink)  
Old 02-19-2007
Jerry Stuckle
 
Posts: n/a
Default Re: getting the current date/time

christopher@dailycrossword.com wrote:
> 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.
>
> -- clh
>
>
> 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...
>> --
>> Rik Wasmus

>
>


Gee, what does the current date/time in microseconds have to do with
data stored in the database? I would think that would be something more
applicable to the language being used.

And I agree with Rik - if you want answers, don't complain about how
inactive this newsgroup is. It's a hell of a lot more active than some
of the newsgroups to which I belong. And most answers here are right on
target - unlike the more active groups which often contain lots of
off-topic posts and spam.

Quantity <> Quality!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #7 (permalink)  
Old 02-19-2007
donalmurtagh@yahoo.co.uk
 
Posts: n/a
Default Re: getting the current date/time

Thanks for the responses. Nobody has suggested a way of getting the
current time showing fractions of a second, so I guess it's just not
possible?

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

donalmurtagh@yahoo.co.uk wrote:
> Thanks for the responses. Nobody has suggested a way of getting the
> current time showing fractions of a second, so I guess it's just not
> possible?
>


This is a system function. I wouldn't expect a relational database to
provide the information. And if one did, I would expect it to be a
bonus, not a standard.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #9 (permalink)  
Old 02-19-2007
donalmurtagh@yahoo.co.uk
 
Posts: n/a
Default Re: getting the current date/time


>
> What exactly are you attempting to accomplish? Fractional seconds are
> seldom reliable anyway, since by the time one gets the result of a
> variable, it's usually not that milisecond anymore...
>


I want to detect whether the difference between the times on 2 boxes
exceeds a certain threshold. I know that I could use NTP in order to
synchronise the times on machines, but the purpose of this exercise is
not to synchronise times, but rather to detect when they're not
synchronised. I appreciate what you're saying about the delay between
executing the query and actually getting the result, but it's still
worth doing in this case.

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

donalmurtagh@yahoo.co.uk wrote:

>
>>
>> What exactly are you attempting to accomplish? Fractional seconds are
>> seldom reliable anyway, since by the time one gets the result of a
>> variable, it's usually not that milisecond anymore...
>>

>
> I want to detect whether the difference between the times on 2 boxes
> exceeds a certain threshold. I know that I could use NTP in order to
> synchronise the times on machines, but the purpose of this exercise is
> not to synchronise times, but rather to detect when they're not
> synchronised. I appreciate what you're saying about the delay between
> executing the query and actually getting the result, but it's still
> worth doing in this case.



So what has SQL got to do with it?

$ perl -MTime::HiRes=gettimeofday -e '$time=gettimeofday();print "$time\n"'
1171908671.04656


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
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:47 AM.


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