Working with Date & Time

I am interacting with a webpage which has 2 elements to save Date and time separately. So i need to get Date and save it in a variable and do the same with time. (Date is in format “DD/MM/YYYY”)

  1. What type of variable should i save the extracted result in?
  2. How can i apply logic to the extracted Date&time to check if that time is less or greater then the current time (using ‘Now’ for current date & time)?

Thanks in advance

Extract the result into string and then convert to DateTime format.
And then use the simple condition to compare the strings -

If dtDateTime < Now Then

Regards,
Karthik Byggari

1 Like

If this is the input format str_input = “dd/M/yyyy”
The use this expression to get the date
Str_date = Split(str_input,”/“)(0).ToString

And to get the time and check whether the time is greater than or not
May I know how you are provided with that as a input
Cheers @ankit002

thanks @KarthikByggari
So after extraction i have 2 string variable (1 containing date and 1 containing time). How do i convert or merge 2 string variables to make a single DateTime variable ?

Thanks @Palaniyappan
Although am afraid i didn’t get the solution. The split command you mentioned is basically providing the date (dd: no month and year) for the extracted Date (dd/MM/yyyy).

How can i make use of this information to check if that date is greater or not from today.
For example if the date i extracted from website is 30/11/2019 and today’s date (which we will get from Now) is 01/12/2019, i cannot compare only the dates for the same.

Also, the format for time is hh:mm:ss

1 Like

Aaha
Got it buddy
Fine
Let’s take like the str_input1 = “dd/MM/yyyy” and str_input2 = “hh:mm:ss”
Now
—use a assign activity like this
Str_input = str_input1+ “ “ + str_input2
—Then a assign like this
date_output = DateTime.ParseExact(str_input,”dd/MM/yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)
Where date_output is a variable of type DateTime

Now we can compare it like this in IF condition which will compare the date and time with today DateTime
DateTime.Now > date_output
If true it will go to THEN part or ELSE part
Hope this would help you
Cheers @ankit002

Create a datetime variable say dtFinal

str1 = Date (consider your date is in format dd/MM/yyyy)
str2 = Time (consider your time is in format hh:mm:ss)

Use Assing Activity with the following expression -

dtFinal = DateTime.ParseExact(str1 + " " + str2,”dd/MM/yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

Regards,
Karthik Byggari

3 Likes

@Palaniyappan, @KarthikByggari thanks to both of you for providing me the solution. Both solution works.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.