Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have script from this script I get to string 1st is 101114(format yymmdd) date 2nd is 162941 (hhmmss) time.

Now want to join these two strings so that I can save it into sql server dated as datetime.

But I don't know to convert this string as dd-mm-yyyy join it with time.

Please help.

Thank you
Seema
Posted

You should investigate DateTime.ParseExact() or the DateTime.Parse() or one of the overrides of either.

http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx[^]

That will get you a DateTime that can be passed to SqlServer.
 
Share this answer
 
v2
Thank you for your question. You can follow the bellow code.

SQL
DECLARE @FormatedDateTime varchar(36)
DECLARE @YourDate char(10)
DECLARE @YourTime char(10)

SELECT @YourDate = '101114'
SELECT @YourTime = '162941'

SELECT @FormatedDateTime = convert(varchar, convert(datetime, @YourDate), 111)
    + ' ' + substring(@YourTime, 1, 2)
    + ':' + substring(@YourTime, 3, 2)
    + ':' + substring(@YourTime, 5, 2)

SELECT FormattedDateTime = @FormatedDateTime



Thanks,
Mamun
 
Share this answer
 
v4
DateTime.ParseExact method and DateTime.TryParseExact, are useful when you have a rare format or a format that confuses DateTime.Parse.
using System;
using System.Globalization;
class Program
{
    static void Main()
    {
        string dateString = "Mon 16 Jun 8:30 AM 2008"; 
        string format = "ddd dd MMM h:mm tt yyyy";
        DateTime dateTime = DateTime.ParseExact(dateString, format,
            CultureInfo.InvariantCulture);
        Console.WriteLine(dateTime);
    }
}


Hope this example will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900