16 DateTime Variable - Uipath Studio

Опубликовано: 27 Апрель 2023
на канале: Sri Guru Tech
84
4

Date Time :

1. Get Current Date in string format:

Datetime.Now.ToString()

(Output - string type - “dd/MM/yyyy hh:mm:ss”)

DateTime.Now

(Output - Datetime variable)

2. Get different formats of datetime as string type

Get current day alone - numerical terms

Datetime.Now.ToString(“dd”)

* Get current day - full text*

Datetime.Now.ToString(“dddd”)

Get Current month - full name

Datetime.Now.ToString(“MMMM”)

Get current month - first three characters

Datetime.Now.ToString(“MMM”)

Get current month - numerical value

Datetime.Now.ToString(“MM”)

Get current year - full year

Datetime.Now.ToString(“yyyy”)

Get current year - last two characters

Datetime.Now.ToString(“yy”)

Get current time - in 12 hrs format

Datetime.Now.ToString(“hh:mm:ss”)

get current time - in 24 hours format

Datetime.Now.ToString(“HH:mm:ss”)

Get current hour alone - 12 hrs format

Datetime.Now.ToString(“hh”)

Get current hours alone - 24 hours format

Datetime.Now.ToString(“HH”)

Get Current minutes

Datetime.Now.ToString(“mm”)

Get current seconds

Datetime.Now.ToString(“ss”)

3. Get current Datetime as string with TIMEZONE
Datetime.Now.ToString(“dd/MM/yyyy hh:mm:ss K”)

4. Get current Datetime with AM / PM
Datetime.Now.ToString(“dd/MM/yyyy hh:mm:ss tt”)

5. Convert a string to Datetime
If input is Strinput = “12/02/2022”

with Convert.ToDatetime method

var_datetime = Convert.ToDatetime(Strinput.ToString)

with Datetime.Parse method

var_datetime = Datetime.Parse(Strinput.ToString)

with Datetime.ParseExact method

var_datetime = Datetime.ParseExact(Strinput.ToString, “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture)

In the above last expression dd/MM/yyyy depends on what format the Strinput variable holds
It has to be same as that
So based on what format we find in string input variable mention the same format instead of “dd/MM/yyyy” in last expression

Note : if you want tour above expression as string output type then include .ToString atlast of the expression

Suppose If the input is of full format

Strinput = “23/11/2022 02:20:31 +5:30”

Then to get this as Datetime

var_datetime = Datetime.ParseExact(Strinput.ToString, “dd/MM/yyyy hh:mm:ss K”)