4D v13.4

Current date

Home

 
4D v13.4
Current date

Current date 


 

Current date {( * )} -> Function result 
Parameter Type   Description
Operator in Returns the current date from the server
Function result  Date in Current date

The Current date command returns the current date as kept by the system clock.

4D Server: If you use the asterisk (*) parameter when executing this function on a 4D Client machine, it returns the current date from the server.

The following example displays an alert box containing the current date:

 ALERT("The date is "+String(Current date)+".")

If you write an application for the international market, you may need to know if the version of 4D that you run works with dates formatted as MM/DD/YYYY (US version) or DD/MM/YYYY (French version). This is useful to know for customizing data entry fields.

The following project method allows you to do so:

  ` Sys date format global function
  ` Sys date format -> String
  ` Sys date format -> Default 4D data format
 
 C_STRING(31;$0;$vsDate;$vsMDY;$vsMonth;$vsDay;$vsYear)
 C_LONGINT($1;$vlPos)
 C_DATE($vdDate)
 
  ` Get a Date value where the month, day and year values are all different
 $vdDate:=Current date
 Repeat
    $vsMonth:=String(Month of($vdDate))
    $vsDay:=String(Day of($vdDate))
    $vsYear:=String(Year of($vdDate)%100)
    If(($vsMonth=$vsDay)|($vsMonth=$vsYear)|($vsDay=$vsYear))
       vOK:=0
       $vdDate:=$vdDate+1
    Else
       vOK:=1
    End if
 Until(vOK=1)
 $0:="" ` Initialize function result
 $vsDate:=String($vdDate)
 $vlPos:=Position("/";$vsDate` Find the first / separator in the string ../../..
 $vsMDY:=Substring($vsDate;1;$vlPos-1) ` Extract the first digits from the date
 $vsDate:=Substring($vsDate;$vlPos+1) ` Eliminate the first digits as well as the first / separator
 Case of
    :($vsMDY=$vsMonth` The digits express the month
       $0:="MM"
    :($vsMDY=$vsDay` The digits express the day
       $0:="DD"
    :($vsMDY=$vsYear` The digits express the year
       $0:="YYYY"
 End case
 $0:=$0+"/" ` Start building the function result
 $vlPos:=Position("/";$vsDate` Find the second separator in the string ../..
 $vsMDY:=Substring($vsDate;1;$vlPos-1) ` Extract the next digits from the date
 $vsDate:=Substring($vsDate;$vlPos+1) ` Reduce the string to the last digits from the date
 Case of
    :($vsMDY=$vsMonth` The digits express the month
       $0:=$0+"MM"
    :($vsMDY=$vsDay` The digits express the day
       $0:=$0+"DD"
    :($vsMDY=$vsYear` The digits express the year
       $0:=$0+"YYYY"
 End case
 $0:=$0+"/" ` Pursue building the function result
 Case of
    :($vsDate=$vsMonth` The digits express the month
       $0:=$0+"MM"
    :($vsDate=$vsDay` The digits express the day
       $0:=$0+"DD"
    :($vsDate=$vsYear` The digits express the year
       $0:=$0+"YYYY"
 End case
  ` At this point $0 is equal to MM/DD/YYYY or DD/MM/YYYY or...

 
PROPERTIES 

Product: 4D
Theme: Date and Time
Number: 33

Different in remote mode

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: < 4D v6

 
SEE ALSO 

Date Operators
Day of
Month of
Year of