0

This is my query,

string sdatevalue = mysdate.ToString("yyyy-MM-dd"); // "2014-02-12"
string stime = txttime.Text;  // 9.00 A.M

replace 9.00 to 9:00 = correcttime;


finaldate=sdatevalue + correcttime;

How to achieve this.

Thanks i want this to be done in asp.net C#

  • Where is your _query_? In general, use sql-parameters with the correct type instead of string concatenation with formatted strings. This prevents several issues, the most important is sql-injection. – Tim Schmelter Sep 19 '14 at 13:19
  • I am using stored procedure for already my date is there in table just want to update the time 00:00:00 as my input time – BeginnerStack1 Sep 19 '14 at 13:24

1 Answers1

2

you might be inserting this into a DataBase which is not a correct approach, its better you do it in your DB itself.

Create a method or extension

string ReplaceFirstOccurenceofCharacter(string text, string search, string replace)
    {
        int pos = text.IndexOf(search);
        if (pos < 0)
        {
            return text;
        }
        return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
    }

and call the method

        string sdatevalue = "2014-02-12";
        string stime = "9.00 A.M";
        string concatinatedstring = string.Format("{0} {1}", sdatevalue, stime);
        var result = ReplaceFirstOccurenceofCharacter(concatinatedstring, ".", ":");

Actual code is pulled from This link Hope it helps you.

Community
  • 1
  • 1
Gowtham.K.Reddy
  • 967
  • 1
  • 9
  • 26