Announcement

Collapse
No announcement yet.

Using PowerTime to get previous week's date

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using PowerTime to get previous week's date

    Hello

    I would like to get the previous week's date, is there a PowerTime function that can have produce -7 days from today's date ?

    I saw the below link , but it only have adddays and no minusdays

    https://forum.powerbasic.com/forum/u...y-simple-query

    Code:
    'powertime in quad
    
    ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/61669-powertime-a-very-simple-query
    
    
    FUNCTION PBMAIN( )
     LOCAL DispDate AS STRING
     LOCAL Built AS IPOWERTIME, qwVal AS QUAD
       LET Built = CLASS "PowerTime"                  ' (internally = Windows FILETIME structure)
    
        ' The current local date and time on this computer is assigned to this PowerTime object
        Built.Now
        MSGBOX Built.DateStringLong, %MB_ICONMASK, "Before"
    
        ' Get a Quad-Integer value of the PowerTime object as a FileTime
        qwVal = Built.Filetime                        ' number of 100nSec periods since Jan 1 1601
    
        ' Change the value
        qwVal = qwVal + (10000000 * 60 * 60 * 24 * 2) ' add two days worth of 100ns to the value
    
        ' Assign the (new) FileTime Quad-Integer value as the PowerTime object value
        Built.Filetime = qwVal
         DispDate = Built.DateStringLong
        MSGBOX " add 2 days date : " + DispDate, %MB_ICONMASK, "After"
    
    Built.AddDays 3  ' add 3 more ~ the easy way :)
        DispDate = Built.DateStringLong
        MSGBOX " add 3 days date : " + DispDate, %MB_ICONMASK, "After the last Display Date"
    
      ' How to have the previous week day  -7 days from today ?
    
    
    END FUNCTION
    Appreciate your help on this

  • #2
    I gotten it resolved as below

    Code:
    FUNCTION PBMAIN( )
     LOCAL DispDate AS STRING
     LOCAL Built AS IPOWERTIME, qwVal AS QUAD
       LET Built = CLASS "PowerTime"                  ' (internally = Windows FILETIME structure)
    
        ' The current local date and time on this computer is assigned to this PowerTime object
        Built.Now
        MSGBOX Built.DateStringLong, %MB_ICONMASK, "Todays date"
    
        ' Get a Quad-Integer value of the PowerTime object as a FileTime
        qwVal = Built.Filetime                        ' number of 100nSec periods since Jan 1 1601
    
        ' Change the value
        qwVal = qwVal + (10000000 * 60 * 60 * 24 * 2) ' add two days worth of 100ns to the value
    
        ' Assign the (new) FileTime Quad-Integer value as the PowerTime object value
        Built.Filetime = qwVal
    
        Built.AddDays -8  ' minus 8 days
        DispDate = Built.DateStringLong
        MSGBOX " Prev 7 days date : " + DispDate, %MB_ICONMASK, "Last week Date"
    
    
        Built.Filetime = qwVal
        DispDate = Built.DateStringLong
        MSGBOX " add 2 days date : " + DispDate, %MB_ICONMASK, "After"
    
        Built.AddDays 3  ' add 3 more ~ the easy way :)
        DispDate = Built.DateStringLong
        MSGBOX " add 3 days date : " + DispDate, %MB_ICONMASK, "After the last Display Date"
    
    
    
    
    END FUNCTION

    Comment


    • #3
      Code:
      FUNCTION PBMAIN( )
       LOCAL DispDate AS STRING
       LOCAL Built AS IPOWERTIME, qwVal AS QUAD
         LET Built = CLASS "PowerTime"                  ' (internally = Windows FILETIME structure)
      
          ' The current local date and time on this computer is assigned to this PowerTime object
          Built.Now
          MSGBOX Built.DateStringLong, %MB_ICONMASK, "Before"
      
        ' How to have the previous week day  -7 days from today ?
          Built.AddDays -7  ' substract 7 days
          DispDate = Built.DateStringLong
          MSGBOX " substract 7 days date : " + DispDate, %MB_ICONMASK, "After the last Display Date"
      
      END FUNCTION
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        Thanxx Jose, I think we solved the issue at the same time.

        Comment


        • #5
          AddDays <1> (ByVal Days&)

          Adds the specified number of days to the value of this object. You can subtract days by using a negative number.
          From Help for IPowerTime. Amazing what's in there, then find demo code in forum for ways to use.

          Cheers,
          Dale

          Comment

          Working...
          X