Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

VB 2008 Regex Time Question

I have the time getting picked date/time picked up like so:
1/8/2010 3:44:58 AM

All i want to know is how can i trim the seconds off so it can read like so:
1/8/2010 3:44 AM

How can i do this using:
System.Text.RegularExpressions.Regex("")
or
any other way will be acceptable as long i can trim the seconds off
0
disrupt
Asked:
disrupt
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Patrick MatthewsCommented:
Hello disrupt,

Regex seems a rather much; why not simply format to m/d/yyyy h:mm AM/PM?

Regards,

Patrick
0
 
disruptAuthor Commented:
how can i do that? what is the expression?
0
 
CsharpCommented:
this is your solution

string localtime = DateTime.Now.ToString("MM/dd/yyyy hh:mm:tt");
Console.WriteLine(localtime);
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
disruptAuthor Commented:
Thing is I do not want the DateTime Now I have a string with a particular date/time in that format
0
 
Bob LearnedCommented:
Convert it to a DateTime, and then convert back to string with the format that you need.

string s = "1/8/2010 3:44:58 AM";
string t = DateTime.Parse(s).ToString("MM/dd/yyyy hh:mm tt");
0
 
CsharpCommented:
this will work check it

string lt = "1/8/2010 3:44:58 AM";

lt = lt.Remove(14,3);
 
you will get the desired result
0
 
Patrick MatthewsCommented:
Csharp said:
>>lt = lt.Remove(14,3);
 
>>
>>you will get the desired result

Careful with that.  If the string is, say, "12/18/2010 10:44:58 AM", then you will get a nasty surprise :)
0
 
CsharpCommented:
No you will not get the nasty surprise
usually system returns the date in format of  01/08/2010 10:44:58 AM
It remains the same , you just have to set your system date in MM/DD/YYYY forma
 
 
0
 
Patrick MatthewsCommented:
Csharp,

For one thing, the Asker specifically indicated that the date/time string is not necessarily being passed from
the system time.  For another looking at the string you just posted, please explain to me how removing 3
characters starting at position 14 yields the desired result.

TheLearnedOne's approach appears best to me...

Patrick
0
 
CsharpCommented:

Mr. Patrick,
Before asking me this question
run this two lines of code on your machine and see by your self.
string lt = "1/8/2010 3:44:58 AM";

lt = lt.Remove(14,3);
Donot ask me foolish questions.
 I am not here to waste my time in arguments with you .
If Author like my solution he will post his comments and points .
You are not judge of my solution .And Who authorize you to  comment on my solution. ? Are you the one who posted the question? . If not then please shut your mouth on other persons solution .
I believe author is intelligent enough , to understand the concept .
 No need of your free judgement service.
 
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now