Converting Date

Hi,

I'm developing an app to send SMS messages and one of the requirements is the 'Send Date & Time' which I need to pass to the provider when sending the message.

On my form there is a Checkbox for the user to click is they want to send the message on a particulr date and time (Send Later), if this isn't checked the message is sent using the current system date and time.

For this I've been using: -

System.DateTime dt = DateTime.Now;

I now want to change my code to include a check to see if the user has selected to 'Send Later' and if so use the selected date from the DateEdit control and time from the TimeEdit control. The If - Else is ok, but I'm having problems setting 'dt' from the date & time controls and converting the strings. This is what I tried: -

System.DateTime dt;

if (chkLater != null)

{

dt = System.DateTime.Now;

}

else

{

dt = dateSend.Text;

}

But I get an error 'Cannot implicitly convert type 'string' to 'System.Date.Time'

Any suggestions on the best way to handle this

PS. How do I display code in my posts more clearly

Regards,

Andrew



Answer this question

Converting Date

  • vbjunkie

    Thanks for the reply.

    The thing is I need to pass through 'System.DateTime' to the WebReference I have in my project. So I need to convert 'string' to 'System.DateTime'.

    Regards


  • snez

    dt = DateTime.Parse(dateSend.Text);

  • OctopusThu

    James,

    Many thanks, much appreciated.

    Regards,

    Andrew


  • AtomZ .be

    you simply need to convert the format to string, their are 3ways of doing this:

    dt = (string)System.DateTime.Now;

    dt = System.DateTime.Now.ToString();

    dt = Convert.ToString(System.DateTime.Now);



  • Converting Date