SQL – Contest to Get The Date – Win USD 50 Amazon Gift Cards and Cool Gift

If you are a regular reader of this blog – you will find no issue at all in resolving this puzzle. This contest is based on my experience with NuoDB.

If you are not familiar with NuoDB, here are few pointers for you.

In today’s contest you have to answer following questions:

Q 1: Precision of NOW()

What is the precision of the NuoDB’s NOW() function, which returns current date time?

Hint: Run following script on NuoDB Console Explorer section:

SELECT NOW() AS CurrentTime
FROM dual;

Here is the image. I have masked the area where the time precision is displayed.

Q 2: Executing Date and Time Script

When I execute following script -

SELECT 'today' AS Today, 'tomorrow' AS Tomorrow, 'yesterday' AS Yesterday
FROM dual;

I will get the following result:

 

NOW – What will be the answer when we execute following script? and WHY?

SELECT CAST('today' AS DATE) AS Today, 
 CAST('tomorrow' AS DATE) AS Tomorrow, 
 CAST('yesterday'AS DATE) AS Yesterday
FROM dual;

HINT: Install NuoDB (it takes 90 seconds).

Prizes:

  • 2 Amazon Gifts
  • 2 Limited Edition Hoodies (US resident only)

 

Rules:

  • Please leave an answer in the comments section below.
  • You must answer both the questions together in a single comment.
  • US resident who wants to qualify to win NuoDB apparel please mention your country in the comment.
  • You can resubmit your answer multiple times, the latest entry will be considered valid.
  • Last day to participate in the puzzle is June 24, 2013.
  • All valid answer will be kept hidden till June 24, 2013.
  • The winner will be announced on June 25, 2013.
  • Two Winners will get USD 25 worth Amazon Gift Card. (Total Value = 25 x 2 = 50 USD)
  • The winner will be selected using a random algorithm from all the valid answers.
  • Anybody with a valid email address can take part in the contest.

Reference: Pinal Dave (http://blog.sqlauthority.com)

About these ads

28 thoughts on “SQL – Contest to Get The Date – Win USD 50 Amazon Gift Cards and Cool Gift

  1. Ans 1) NuoDB provides timestamp information to the microsecond (6 decimal places) of precision.
    Query Result 2013-06-20 07:48:31.450723

    Ans 2) TODAY TOMORROW YESTERDAY —> 2013-06-20 2013-06-21 2013-06-19
    Reason:- Because NuoDB supports literals (‘now’, ‘today’, ‘yesterday’ and ‘tomorrow’) that can be used as values for date.

  2. Q1: Precision of NOW().
    NuoDB provides timestamp information to the microsecond (6 decimal places), so the precision will be 6.
    Q2: Executing Date and Time Script.
    NuoDB supports literals ‘today’, ‘yesterday’ and ‘tomorrow’ as values for date and the correct syntax is: CAST(‘today’ AS DATE) AS Today, CAST(‘yesterday’ AS DATE) AS Yesterday and CAST(‘tomorrow’ AS DATE) AS Tomorrow.

  3. 1. microsecond precision
    2. the output will contain relevant dates because you’re casting as such and the sql engine is equipped to handle those string literals.

  4. Fantastic responses so far. I am very confident that there is going to be a winner of such a cool gift. All the valid responses will be displayed after the contest is over.

  5. Q1: Precision of NOW()
    What is the precision of the NuoDB’s NOW() function, which returns current date time?
    SELECT NOW() AS CurrentTime
    FROM dual;
    Answer: 2013-06-20 11:02:48.063512
    1) NuoDB provides Time Precision of NOW () as MICROSECOND (6 decimal places).
    2) NOW() is equivalent to CAST( ‘now’ AS Timestamp)

    Q2: Executing Date and Time Script
    What will be the answer when we execute following script? and WHY?
    SELECT CAST( ‘today’ AS DATE) AS Today,
    CAST(‘tomorrow’ AS DATE) AS Tomorrow,
    CAST(‘yesterday’ AS DATE) AS Yesterday
    FROM dual;

    Output: ( If today date is 20th June, 2013)
    TODAY TOMORROW YESTERDAY
    ———- ————- ————-
    2013-06-20 2013-06-21 2013-06-19

    Reason:
    1) NuoDB supports literals (‘now’, ‘today’, ‘yesterday’ and ‘tomorrow’) that can be used as values for DATE.
    2) Those literals are considered as strings when used for varchar

  6. i done work on this it is very good it used a great intelligence.below i answered 2 of your question.

    (1)first question answer.

    today tomorrow yesterday
    2013-06-20 2013-06-21 2013-06-19

    2.why means

    in the above query you used a cast function so the functionality of cast is to convert one data type to another it works good in “sql server.”

    but “NUODB” supports literals (‘today’, ‘yesterday’ and ‘tomorrow’) that can be used as values for “date” so we can do this by using those literals and we can also use one more literal ‘now’ i done some practicals on this it seems work

    In “NUODB” the use of cast function is it converts the date into required literals format

    here i will show you how to use ‘now’ literal.in NUODB

    select cast(‘now’ as date) from dual
    once we click on execute button in nuodb we will see the today’s date.

    i think my comment is some what good.

    i am from INDIA,
    mail id:-Munnangiavinashreddy@gmail.com

    Thanks in advance,
    Avinash Reddy Munnnangi.

  7. Q1: The NOW() function returns values up to microseconds (6 decimal places).

    Q2: The result is:

    TODAY TOMORROW YESTERDAY
    2013-06-20 2013-06-21 2013-06-19

    The given strings in the CAST() function are used as literals for the DATE type.

    (Iowa, USA)

  8. Q 1: Precision of NOW()
    A 1:
    NOW() : no precision 2013-06-20 13:11:11
    but
    cast(‘now’ as timestamp) : 2013-06-20 13:11:11.074721

    Q 2: Executing Date and Time Script
    A 2:
    Today Tomorrow Yesterday
    ———- ———- ———-
    2013-06-20 2013-06-21 2013-06-19

    Because, NuoDB supports literals (‘now’, ‘today’, ‘yesterday’ and ‘tomorrow’) that can be used as values for date.

  9. Answer: 2013-06-20, 2013-06-21, 2013-06-19 Why: because cast define today as todays’s Date, tomorrow as tomorrow’s date and yesterday’s as yesterday’s date in NueDB

  10. SELECT NOW() AS CurrentTime
    FROM dual; — the precision is 1

    SELECT CAST(‘today’ AS DATE) AS Today, — > This gives the current day date
    CAST(‘tomorrow’ AS DATE) AS Tomorrow, —-> tomm date
    CAST(‘yesterday’AS DATE) AS Yesterday ——> yesterday date
    FROM dual;

  11. USA
    #1 – It is in fractional seconds precision (milla seconds)

    #2 – Today: 2013-06-20
    Tomorrow: 2013-06-21
    Yesterday: 2013-06-019

    CAST() as DATE. Neat how it took the string of Today and new it was a NOW() and how the others the same translation from string to DATE ADD in a sense….

  12. Q1. MICROSECONDS

    Q2.
    current date, tomorrow date,yesterday date.
    today,tomorrow and yesterday are date time function CAST

    US,

  13. ans 1. last 7 digits will be mili & nano seconds.
    ans 2. dual is used when we dont now the actual table name. so it does not have any data inside. and when we execute data is not there and it will display like this. as ans 2.

  14. 1) Select NOW() AS CurrentTimeFROM Dual;
    Answer: 2013-06-24 16:30:20.342516
    Precision of the NuoDB’s NOW() function is 6 decimal places (MICROSECOND)
    2) SELECT CAST(‘today’ AS DATE) AS Today, CAST(‘tomorrow’ AS DATE) AS Tomorrow, CAST(‘yesterday’ AS DATE) AS Yesterday
    FROM dual;
    Answer:
    TODAY TOMORROW YESTERDAY
    ———- ————- ————-
    2013-06-24 2013-06-25 2013-06-23
    Reason: ‘today’, ‘tomorrow’, ‘yesterday’, ‘now’ are the literals that can be used as values for DATE…Here we casted those literals to DATE type.
    Query returns respective Today, Tomorrow, and Yesterday’s dates…

  15. NuoDB is a very nice product. I downloaded it immediately after reading this artile.
    Here is my answer :
    Precision of NOW() will display current date
    When we we execute following script we get result Today Tomorrow Yesterday

  16. By running following script
    SELECT NOW() AS CurrentTime
    FROM dual;
    Answer 1 : shows Current time

    when we execute following script
    SELECT CAST(‘today’ AS DATE) AS Today,
    CAST(‘tomorrow’ AS DATE) AS Tomorrow,
    CAST(‘yesterday’AS DATE) AS Yesterday
    FROM dual;

    Answer 2:
    Today Tomorrow Yesterday
    25-6-2013 26-6-2013 24-62013

  17. First syntax will display current time with the precision of millisecond

    Second answer is Today 25/6/2013
    Tomorrow 26/6/2013
    Yesterday 24/6/2013

  18. Hi Team,

    I apologize for the delay. I just got the result back from the team.

    Here are the name of the winners:

    USD 50 Amazon Gift Card
    Samy
    Elie

    NuoDB Hoodies
    Michael Buescher
    James

    Please send your address with phone number to ship the hoodies and valid email address to get USD 50 Amazon gift card to pinal at SQLAuthority.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s