1. Arthur Foux
  2. PowerBuilder
  3. Wednesday, 11 December 2019 06:54 AM UTC

How do I display and save current Today() Now(), formatted (m/d/yyyy h:mm am/pm).

Thank You.

Michael Kramer Accepted Answer Pending Moderation
  1. Thursday, 12 December 2019 13:26 PM UTC
  2. PowerBuilder
  3. # 1

Hi Arthur, what timestamp are you interested in?

  1. Local PC, current timezone/regional settings? ==> PowerScript
    datetime ldt_current
    ldt_current = DateTime(Today(), Now())​
  2. Local PC, current UTC timestamp? ==> Use Windows API
    TopWiz Programming's FileSys sample demos how to manage WinAPI's SystemTime.
    // EXTERNAL FUNCTION
    PRIVATE SUBROUTINE GetSystemTime(REF winapi_systemtime) library "kernel32.dll" alias for "GetSystemTime"​
  3. Database server's local time?
    In this case I use MSSQL for sample code. Oracle, SQL Anywhere, SAP ASE, and others have similar functions
    // Note embedded SQL requires FROM clause
    datetime ldt_current
    SELECT [Today_Now] INTO :ldt_current
    FROM (SELECT GetDate() AS [Today_Now]) data​
  4. Database server's UTC time?
    In case you trust the DB server better than clock on a random pc
    // Note embedded SQL requires FROM clause
    datetime ldt_current
    SELECT [Today_Now] INTO :ldt_current
    FROM (SELECT GetUtcDate() AS [Today_Now]) data​​L 

Local PC's time may be too "fragile" for your app. In that case I suggest query your database server.

HTH /Michael

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 11 December 2019 07:23 AM UTC
  2. PowerBuilder
  3. # 2

Hi Arthur,

I'm not sure what you want.

To display current clients date time in this format you may use the string function to convert or a display format for a today() computed field in a datawindow.

e.g. String(today(), "m/d/yyyy h:mm am/pm")

If you use a datawindow with computed field you may keep the field automatically updated if you set the "Timer Interval" property of the datawindow. It specifies the number of milliseconds after the timer updates the computed fields. It is 0 by default.

HTH,

René

Comment
  1. Michael Kramer
  2. Thursday, 12 December 2019 12:35 PM UTC
Side Note: Don't assign Today/Now in declaration as default value, nor define it as a constant!

Both are evaluated at COMPILE time so you get date/time of compilation.

Yo have have to assign the value in an assignment statement, e.g. first line in Constructor event.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.