String (00:00:30) to TimeSpan

This is my RetryIntervel Time duration “00:00:30”

how to convert into Timestamp through config variable.

Thanks in advance.

@ManjunathReddy

  1. Variables

    • retryInterval (Type: String)
    • timestamp (Type: DateTime)
  2. Assign Activity

    • To: retryInterval
    • Value: New TimeSpan(0, 0, 30).ToString
  3. Assign Activity

    • To: timestamp
    • Value: DateTime.Now.Add(TimeSpan.Parse(retryInterval))
  4. Use the ‘timestamp’ variable as needed in your workflow.

Refer below file as refernce
test.zip (2.4 KB)

Hope it helps you out

Hi @ManjunathReddy

Strinput = “00:00:30”

var_timespan = TimeSpan.Parse(Strinput.ToString)
//Note: DataType of var_timespan is System.TimeSpan

var_timestamp= DateTime.Now.Add(var_timespan)
//Note: DataType of var_timestamp is System.DateTime



Sequence1.xaml (7.2 KB)

Hope it helps!!

Another option is just to put the number of seconds into the config file. Then you can simply use

TimeSpan.FromSeconds(CInt(Config(“timeStamp”).ToString))

1 Like

@ManjunathReddy
How about following syntax.

@postwick

@ManjunathReddy

Can you show how you saved the value in config…looks like the cell is formatted as date…try to convert to general and just save 30 and then use the formula

Cheers

@Anil_G

I have used this.

TimeSpan.FromSeconds(CInt(Config(RetryInteraval).ToString))

Hi @ManjunathReddy
Try this:

TimeSpan.FromSeconds(Convert.ToInt64(Config(RetryInterval).ToString()))

Hope it helps!!

@ManjunathReddy

I understood the formula…but value you are getting from config looks like a timestamp…try to change that in config and it should work

Cheers

just do this
timespan.FromSeconds(30)

@Anil_G

In the config the Value (00:00:03) is Text type.

I have used These two syntaxes but no use.

TimeSpan.FromSeconds(CInt(Config(RetryInteraval).ToString))
TimeSpan.FromSeconds(CDbl(Config(RetryInteraval).ToString))

Thanks

@ManjunathReddy

Give only 3 or30 in config and not 00:00:03

Hope this is clear

Cheers

Hi @ManjunathReddy
Try this syntax:

TimeSpan.FromSeconds(Convert.ToInt64(Config(RetryInterval).ToString()))

Hope it helps!!

Because you’ve typed 00:00:30 into Excel it has interpreted it as a datetime and when you read the value you’re getting 12/30/1899 00:00:30. This is one of the reasons I suggested just putting the number of seconds into Excel and then using TimeSpan.FromSeconds

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