Remove certain words from string and get hours

Hi Folks,

I have two questions. The first one is if I have an address of this format: “1654 Beltline Road SW, Decatur, AL 35601, US” and I want to remove the ending part like the output I want is: “1654 Beltline Road SW, Decatur, AL 35601”. I want to remove the ending part. Can someone help me with some efficient way to remove this part?

Second one. If I am receiving a date and time like “4/29/2023 8:00 AM”. Now what I want is hours between the current date and time minus the time that is in the string. I want the time in hours. Can someone help me with this too?

Big thanks in advance. :slight_smile:


Try this

  1. String.Join(",",Str.Split({","},Stringsplitoptions.None).SkipLast(1).ToArray)
  2. Now.Subtract(Datetime.ParseExact("datestring","M/d/yyyy h:m tt",System.Globalization.CultureInfo.InvariantCulture)).TotalMinutes


are you looking for this?



Hello, Umer.

This would be another idea for the first part.

  1. Assign str_address="1654 Beltline Road SW, Decatur, AL 35601, US"
  2. Assign LastIndexOfComma=str_Address.LastIndexOf(",")
  3. To get the value will be str_Address.Substring(0,LastIndexOfComma)

If you want all together in one line will be str_Address.Substring(0,str_Address.LastIndexOf(","))

For the second part you can follow what @Anil_G shows

Can you replace the second one with Given date time - current date time (eastern time)?


The given query is same

  1. Now.Subtract(Datetime.ParseExact("datestring","M/d/yyyy h:m tt",System.Globalization.CultureInfo.InvariantCulture)).TotalMinutes

Now is current time and datestring is the string you have


What you wrote is Current time - given time which return negative value. I want given time - current time.


Please check

  1. Datetime.ParseExact("datestring","M/d/yyyy h:m tt",System.Globalization.CultureInfo.InvariantCulture).Subtract(Now).TotalMinutes


Lemme try. One more question can we get current eastern time (USA) not the machine time?


TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"))


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