Link to home
Start Free TrialLog in
Avatar of techques
techques

asked on

var strDate = '<%= System.DateTime.Now.ToString(\'yyyy-MM-dd\'); %>';

Hi

I write asp.net, c# and javascript

In the js, I need to get the system datetime and in the format yyyy-MM-dd

However, it has runtime error.
var strDate = '<%= System.DateTime.Now.ToString(\'yyyy-MM-dd\'); %>';
 
or
 
var strDate = '<%= System.DateTime.Now.ToString(\"yyyy-MM-dd\"); %>';

Open in new window

Avatar of abel
abel
Flag of Netherlands image

Try:

'<%= System.DateTime.Now.ToString("yyyy-MM-dd"); %>';

I don't know why you put in the backslashes there, but you are not inside a string, so they are not necessary.
Avatar of techques
techques

ASKER

It has compile error:

CS1026: ) expected


ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>is that just for formatting?
yup, with some other features like doing validation and parsing for date string, etc. cheers
Thanks for all help. I add more points for all experts.
> Thanks for all help.

you're welcome, glad we could have been of some help.

However, as a long-time regular to EE I have to point you to the fact that it is best to just split the points and not except your own comment (which is not an answer) as answer. That way, people visiting this question get the correct answer and the PAQ archive of EE stays proper.

-- Abel --