How to extract Hours,minutes,seconds from a date

studio
variable

#1

Suppose I have a time field in excel which I need to use but the field on the webpage wants time in the separate form of hours, minutes and seconds.image.
Could anyone help regarding this.


#2

@ashutoshkhantwal,

hour - dateVariable.ToString(“HH”) if you need it in 24 Hours Format
and dateVariable.ToString(“hh”) if you need it in 12 Hours Format
minutes - dateVariable.ToString(“mm”)
seconds - dateVariable.ToString(“ss”)

Regards,
Dominic :slight_smile:


#3

It wasn’t successful


#4

@ashutoshkhantwal, Where do you find it hard ?

Regards,
Dominic :slight_smile:


#5

It is a dynamic data not static one, hence this won’t work.


#6

Hi @ashutoshkhantwal,

It will work.
check before dateVariable data type must in DateTime else convert the string to datetime convert.ToDateTime(dateVariable)

use the above code.

@ashutoshkhantwal In What format you are getting the input???

Regards,
Arivu


#7

The input is a generic variable, the format is HH:mm:ss.


#8

If you are getting HH:mm:ss format then split the value using :
and get the hour,min,sec
For Example ->Generic Variable ->GvDateTime (11:15:00)
create splittime variable and datatype->string[]
assign splittime=GvDateTime.ToString().Split(":")

Hour- >splittime(0) ---->11
Min- >splittime(1)------->15
Sec- >splittime(2)------->00

the other way is you need to convert hh:mm:ss into time then get the values.
string userInput = "15:43:13"
create TimeSpan varible ->timeval
assign timeval=TimeSpan.Parse(userInput)
timeval.hours.Tosting ->hour
timeval.Minutes.Tosting ->min
timeval.Seconds.Tosting -> sec

Regards,
Arivu


#9

Hi @ashutoshkhantwal,

Please find attached sample workflow for your requirement.

Test_2.xaml (7.1 KB)

Reg,
Sarthak


#10

Hey Arivu,Thanks this worked though I used something different in addition to this since the cell was of format custom. Had to format that to a date time variable using format value/assign activity.