[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Check if String has a Valid Time

Posted on 2011-03-03
3
Medium Priority
?
487 Views
Last Modified: 2012-05-11
I have clients passing a string to my WCF Service for processing using an SQL SP. One of the parameters they pass is a String Value, which should be a DateTime in String Format. (Service does all TryParse etc..)

This must stay as it is, as other services use this which I can't change.

What I need to do is somehow Check the String server side, to see if the String has a valid time, as well as a Date, before I pass it to the SP. If it doesn't, I need to add a time of '23:59:59.997', if it has, then I leave it alone, because one the the clients has specified a Time in their request. (i.e. some clients pass '2011/2/21' other might pass '2011/2/21 14:14:00'.

The point is that sometimes a client passes a String with Date AND Time, other times the client may pass a Datetime in ShortDate format.

I can't change the client, so need to do the checking server side.

Thanks.
0
Comment
Question by:wint100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35030943
Would this be adequate?
string incoming_string = "2011/2/21 14:14:00";
DateTime parsedDate;

if (DateTime.TryParse(incoming_string, out parsedDate))
{
    // Date is valid

    string partial = incoming_string.Trim();

    partial = partial.Substring(partial.LastIndexOf("/") + 1);

    if (partial.Length <= 2)
    {
        // No time was entered
        parsedDate = parsedDate.AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(997);
    }
}
else
{
    // Date invalid
}

Open in new window

0
 
LVL 1

Author Comment

by:wint100
ID: 35036371
That should do it, thanks.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35037026
NP. Glad to help  : )
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question