Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Type conversions in AdvPL

Chooses explicit formats for date and number conversion.

Type conversions in AdvPLAdvPL
01 · OVERVIEW

Overview

CTOD interprets date text under environment formatting and DTOC displays it; ambiguous text is not portable. DTOS produces YYYYMMDD and STOD reverses that contract. STR pads spaces and StrZero pads zeros; insufficient width can produce asterisks. Val reads a numeric prefix rather than validating the whole input: decimal points and trailing text need handling. This example uses an unambiguous date and fixed number. (Sources: refs. 1–7.)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed408()
    Local dDate := SToD("20261026")
    // Explicit interchange format without changing SET DATE.
    ConOut(DToS(dDate))
    ConOut(DToC(dDate))
    ConOut(cValToChar(CToD(DToC(dDate)) == dDate))
    ConOut(Str(12,4,0))
    ConOut(StrZero(12,4,0))
    ConOut(cValToChar(Val("12.5")))
Return Nil
Expected result

20261026; environment-formatted date; true equality under prepared formatting; " 12"; "0012"; number 12.5. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Validate input before conversion and check width, separator and century.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. CToD. TDN. Accessed on 2026-10-26.
  2. TOTVS. DToC. TDN. Accessed on 2026-10-26.
  3. TOTVS. DToS. TDN. Accessed on 2026-10-26.
  4. TOTVS. Str. TDN. Accessed on 2026-10-26.
  5. TOTVS. StrZero. TDN. Accessed on 2026-10-26.
  6. TOTVS. Val. TDN. Accessed on 2026-10-26.
  7. TOTVS. STOD(). TDN. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha