You must Sign In to post a response.
  • Category: ASP.NET

    Sql datetime format issue

    i am saving 'patientadmissiondate' field as DateTime.Now;. When i view table data i see the values in this column in this format '11/24/2015 10:46:05 AM'..
    however when i do select * from tbpatientadmissiondate i see the values in this column as '2015-11-24 10:46:05.443'
    Due to this i am having issue returning the records which match a particular 'patientadmissiondate' .Please guide!
  • #763271
    Hello Sp,

    You can simply use this query :

    SELECT DATE_FORMAT(Memo_Date,'%d/%m/%Y') AS Date
    FROM patientadmissiondate;

    See the attached image. It's an output of this code.

    Hope this is what you looking for. The query i have mentioned here is for MySQL.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763273
    11/24/2015 10:46:05 AM.. i want to save values in this format.. also when i do select * from tb .. the date format should be 11/24/2015 10:46:05 AM

  • #763274
    Hello sp,

    You can not store values in dd/MM/yyyy format in any database. Because none of the database support the dd/MM/yyyy format to store the date value.

    You must store the date MM/dd/yyyy format in SQL and yyyy/MM/dd in MySQL Format.

    You can retrieve the value as per your need like this :
    SELECT DATE_FORMAT(Memo_Date,'%d/%m/%Y %T %p') AS Date
    FROM patientadmissiondate;


    See the attached image. You will get an output like this.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763279
    Hi SP,

    That's totally depend upon your datatype of the particular field instead of worrying about storing format, I request you to please elaborate your actual issue. So, that we can help you better.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763325
    Hello,

    Try with this :-

    SELECT convert(varchar(50),DateField,131) AS DATE FROM TableName

    TableName - provide your table name
    DateField - provide date column name

    Hopefully it solve the issue.


    Thanks


Sign In to post your comments