Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    2

    Post Unanswered: boring for datetime manipulation

    here the question bored me,I'm waiting for some advices

    one table store exact hour in integer

    teq(teq_time interger,----exact hour,such as 10 for 10:00:00
    cond varchar(24))

    extend(extend((current- interval(1) day to day),year to day),year to second) + teq_time;

    eg,teq_time=10
    such as current time is 2005-10-27 12:00:00
    my procedure should return as 2005-10-26 10:00:00

    cause interval () hour to second is not allowed in variable.

    I wanna build one procedure to create time for execute another procedure.another procedure parameter is datetime year to second.

    how can i do?

  2. #2
    Join Date
    Feb 2005
    Posts
    43
    If I understand correctly just what it is that you want to do, my best guess to help you out would be to try something like this:

    extend(today - 1 units day, year to second) + teq_time units hour;

    One of the problems you'll face with 'current' rather than 'today' is that you'll get the current time as well as the current date. Extending 'today' will give you zeros for hour to second so you will start with a clear time.

    HTH.

  3. #3
    Join Date
    Oct 2005
    Posts
    2
    but teq_time is integer
    I'd got one datetime year to second as a return
    how to from today ,teq_time to reach a datetime datatype

  4. #4
    Join Date
    Feb 2005
    Posts
    43
    Did you try it? If not, try this to see for yourself how it works:

    select extend(today - 1 units day, year to second)
    from systables
    where tabid = 1;

    You will end up with: 2005-10-27 00:00:00



    Now try this:

    select extend(today - 1 units day, year to second) + 10 units hour
    from systables
    where tabid = 1;

    You will have this:
    2005-10-27 10:00:00

    (Note that today is 28 October 2005.)

    EXTEND is extending the DATE (today - 1 units day) to a DATETIME YEAR TO SECOND value. As you can see in the first returned expression, the HOUR TO SECOND value is 00:00:00. In the second expression I added "10 units hour". You would use the integer value stored in teq_time as the UNITS HOUR portion of the example.

    In your original example, you used the CURRENT keyword to start with a DATETIME. That is not necessary. If you use the TODAY keyword instead, you'll get the results as shown above.

    Does that help clear it up?

Posting Permissions

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