-2

I need the current date so I am writing a below code

dateCreated = new Date();

which returns Thu Dec 05 2013 12:57:48 GMT+0530 (India Standard Time).

But when I am trying to store it into database it is showing an error

I am using DateTime datatype to store date in SQL Server 2012 database

I even tried using Date datatype but it is showing me error.

Is there any way to do this?

I just want to store date

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Trupti
  • 597
  • 4
  • 8
  • 17

2 Answers2

1

You need to put it in a format that SQL understands. It doesn't understand the string Thu Dec 05 2013 12:57:48 GMT+0530 (India Standard Time) just format it how SQL likes it.

e.g. YYYY-mm-dd

Johnno Nolan
  • 29,228
  • 19
  • 111
  • 160
0

Format the date according your need

function getDate() {  
    TDate = new Date(); 
    CurYear = TDate.getYear();
    CurMonth = TDate.getMonth();
    CurDay = TDate.getDate();
    CurHour = TDate.getHours(); 
    CurMins = TDate.getMinutes(); 
    CurSecs = TDate.getSeconds();

    CurDay = ((CurDay < 10) ? '-0' : '-') + CurDay;
    CurMins = ((CurMins < 10) ? ':0' : ':') + CurMins;
    CurSecs = ((CurSecs < 10) ? ':0' : ':') + CurSecs;

    TheDate = '';
    TheDate += ((CurYear%1900)+1900) + '-';
    TheDate += CurMonth;
    TheDate += CurDay + ' ';
    TheDate += CurHour;
    TheDate += CurMins;
    TheDate += CurSecs;
    return TheDate;
}

alert(getDate()); //YYYY-MM-DD HH:MM:SS
Vipin Kumar Soni
  • 826
  • 10
  • 18