Professional Web Applications Themes

getting the current date/time - MySQL

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

  1. #1

    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

    donalmurtagh@yahoo.co.uk Guest

  2. #2

    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, co.uk wrote: 


    christopher@dailycrossword.com Guest

  3. #3

    Default Re: getting the current date/time

    On Sun, 18 Feb 2007 18:21:32 +0100, <com> wrote:
     

    But that still won't give you the _current_ microseconds...
    --
    Rik Wasmus
    Rik Guest

  4. #4

    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 <com> wrote: 
    >
    > But that still won't give you the _current_ microseconds...
    > --
    > Rik Wasmus[/ref]


    christopher@dailycrossword.com Guest

  5. Moderated Post

    Default Re: getting the current date/time

    Removed by Administrator
    Rik Guest
    Moderated Post

  6. #6

    Default Re: getting the current date/time

    com wrote: 
    >> But that still won't give you the _current_ microseconds...
    >> --
    >> Rik Wasmus[/ref]
    >
    >[/ref]

    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.
    net
    ==================
    Jerry Guest

  7. #7

    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?

    donalmurtagh@yahoo.co.uk Guest

  8. #8

    Default Re: getting the current date/time

    co.uk wrote: 

    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.
    net
    ==================
    Jerry Guest

  9. #9

    Default Re: getting the current date/time

    On 18 Feb 2007 17:30:27 -0800, 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...

    --
    95. My dungeon will have its own qualified medical staff complete with
    bodyguards. That way if a prisoner becomes sick and his cellmate tells the
    guard it's an emergency, the guard will fetch a trauma team instead of
    opening up the cell for a look. --Peter Anspach's Evil Overlord List
    Peter Guest

  10. #10

    Default Re: getting the current date/time

     

    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.

    donalmurtagh@yahoo.co.uk Guest

  11. #11

    Default Re: getting the current date/time

    co.uk wrote:
     
    >
    > 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.[/ref]


    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
    Brian Guest

  12. #12

    Default Re: getting the current date/time



    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 Guest

  13. #13

    Default Re: getting the current date/time

    On 19 Feb 2007 10:03:24 -0800, co.uk wrote: 
    >
    > 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.[/ref]

    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?

    --
    9. If a self-destruct mechanism is necessary, it will not be a large red button
    labelled "Danger: Do Not Push". The big red button marked "Do Not Push" will
    instead trigger a spray of bullets on anyone stupid enough to disregard it.
    --Peter Anspach's list of things to do as an Evil Overlord
    Peter Guest

  14. Moderated Post

    Default Re: getting the current date/time

    Removed by Administrator
    Jerry Guest
    Moderated Post

  15. Moderated Post

    Default Re: getting the current date/time

    Removed by Administrator
    christopher@dailycrossword.com Guest
    Moderated Post

  16. Moderated Post

    Default Re: getting the current date/time

    Removed by Administrator
    Rik Guest
    Moderated Post

  17. Moderated Post

    Default Re: getting the current date/time

    Removed by Administrator
    donalmurtagh@yahoo.co.uk Guest
    Moderated Post

  18. #18

    Default Re: getting the current date/time

     

    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 Guest

  19. Moderated Post

    Default Re: getting the current date/time

    Removed by Administrator
    Jerry Guest
    Moderated Post

  20. #20

    Default Re: getting the current date/time

    On 19 Feb 2007 18:38:18 -0800, co.uk wrote: 
    >
    > 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.[/ref]

    So turn on the NTP service on those other hosts, and write a java client
    that polls them for their current time.

    http://ntp.isc.org/bin/view/Support/JavaSntpClient

    --
    The consquences of any action will never be fully understood until after
    it's too late to do anything about it.
    -- Schwartz's Second Law
    Peter Guest

Page 1 of 2 12 LastLast

Similar Threads

  1. Get current date/time? Use them in hidden field?
    By EvolvedDSM in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: May 10th, 07:10 AM
  2. How To Include Current Time and Date in Form
    By DawnPaul in forum Macromedia Dynamic HTML
    Replies: 2
    Last Post: October 26th, 02:12 PM
  3. Saving current date and time in ASP and ACCESS
    By Amcasperforu in forum Dreamweaver AppDev
    Replies: 5
    Last Post: April 19th, 05:20 PM
  4. <<Current Date>> time warp?
    By DavidF in forum FileMaker
    Replies: 2
    Last Post: December 5th, 03:48 PM
  5. Current Date & Time
    By R3iam webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 4
    Last Post: July 19th, 12:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139