why this code doesnt work?
Code:DateTime1.Text = datetime.now
Printable View
why this code doesnt work?
Code:DateTime1.Text = datetime.now
What does the error message say? Something like "cannot convert DateTime to String"? The Text property of any control expects a String object. The DateTime.Now property returns a DateTime object. You cannot stick a square peg in a round hole.
You could convert the DateTime object to a String by calling one of its methods, like ToString, but I'm guessing that DateTime1 refers to a DateTimePicker control. If that's the case then you should never be setting its Text property. You should be setting its Value property:The Value property is type DateTime.C# Code:
DateTime1.Value = DateTime.Now;
You should always read the documentation for the classes you're using, particularly if they don't work the way you expect. If you'd done that you probably could have solved this on your own.