[RESOLVED] Converting Date  
Author Message
Mirific201201





PostPosted: Visual C# General, [RESOLVED] Converting Date Top

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



Visual C#4  
 
 
Develop3r





PostPosted: Visual C# General, [RESOLVED] Converting Date Top

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);



 
 
Mirific





PostPosted: Visual C# General, [RESOLVED] Converting Date Top

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


 
 
James Curran





PostPosted: Visual C# General, [RESOLVED] Converting Date Top

dt = DateTime.Parse(dateSend.Text);

 
 
Mirific





PostPosted: Visual C# General, [RESOLVED] Converting Date Top

James,

Many thanks, much appreciated.

Regards,

Andrew