<cDateTime>.ToString

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > Date and Time > cDateTime > cDateTime_Methods >

<cDateTime>.ToString

 

Description

 

Handy function returning current date and time in a string form.

 

Syntax

 

Option 1: numeric format option

s = <cDateTime>.ToString[(lFormat)]

 

Option 2: string format option

s = <cDateTime>.ToString(strFormat)

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

lFormat

Numeric

Yes

If format parameter is numeric or missed, use one of those values to  indicate return string formats.
 

Possible other formatting types:

0YYYY/MM/DD HH:mm:ss.SSS
1YYYY/MM/DD
2DD/MM/YYYY HH:mm:ss.SSS
3YYYY-MM-DD

 

10YYYY-MM-DD HH:MM:SS
11YYYYMMDD_HHmmssSS

 

20YYYYMMDDHHmmssSS

 

31YYYYMM

 

strFormat

String

yes

Specify style format string and return the date/time in that format, supporting placeholders like yyyy, MM, dd, HH, mm, ss, fff, tt, dddd, MMM, etc.

 

Warning: all placeholders are case sensitive

 

Supported Format Tokens

Token

Meaning

Example

yyyy

4-digit year

2025

yy

2-digit year

25

MMMM

Full month name

August

MMM

Abbreviated month name

Aug

MM

Month (01-12)

08

M

Month (1-12)

8

dddd

Full day of week name

Sunday

ddd

Abbreviated day of week name

Sun

dd

Day of month (01-31)

07

d

Day of month (1-31)

7

HH

Hour in 24-hour format (00-23)

14

H

Hour in 24-hour format (0-23)

14

hh

Hour in 12-hour format (01-12)

02

h

Hour in 12-hour format (1-12)

2

mm

Minute (00-59)

09

m

Minute (0-59)

9

ss

Second (00-59)

05

s

Second (0-59)

5

fff

Milliseconds (000-999)

073

tt

AM/PM

AM

t

A/P

A

 

1.Locale‑aware names: "dddd" / "ddd" / "MMMM" / "MMM" returns localized day/month strings from Windows.

2.Literal text: single quotes wrap verbatim text; doubled '' becomes a single quote (like .NET).

3.Escapes: \ makes the next character literal (e.g., H\h m\m ⇒ 13h 05m).

4.AM/PM rules: 00:00:00 → 12:00:00 AM; 12:00:00 → 12:00:00 PM.

 

 

 

Remarks

 

Restrictions

 

See also

 

Examples

 

' Create an object with current date and time

Dim myDateTime As New cDateTime

 

' Displays the current time and date

MsgBox 0, "myDateTime is:" + $CRLF + myDateTime.toString        

MsgBox 0, "myDateTime is:" + $CRLF + myDateTime.toString(10)

MsgBox 0, "myDateTime is:" + $CRLF + myDateTime.toString("yyyy/MM/dd HH:mm")