How to convert "string" to "timestamp without time zone"

I am new to Postgresql and I am using WCF services. Here is my code snippet:

$.ajax({
    url: '../Services/AuctionEntryServices.svc/InsertAuctionDetails',
    data: JSON.stringify({ "objAuctionEntryEntity": {
        "AuctionNO": '',          
        "AuctionDate": $('[Id$="lblAuctionDateVal"]').text(),
        "TraderID": $('[Id$="ddlTraderName"] option:selected').val(),
        "Grade": $('[Id$="ddlGrade"] option:selected').val(),
        "Varity": $('[Id$="ddlVarity"] option:selected').val(), 
        "QuntityInAuction": $('#txtQuantityForAuction').val(),
        "AuctionRate": $('#txtAuctionRate').val(),
        "BrokerID": a[0],
        "IsSold": $('#chlIsSold').is(':checked'),
        "CreatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
        "UpdatedBy": $.parseJSON(GetCookie('Admin_User_In_Mandi')).UserID,
        "CreationDate": GetCurrentDate().toMSJSON(),
        "IsActive": true,
        "AuctionTransaction": arrAuctionTransaction,
        "MandiID": $.parseJSON(GetCookie('Admin_User_In_Mandi')).MandiID,
        "FarmerID": _ownerid,
        "AuctionNO": _auctionno,
        "AmmanatPattiID": _ammantpattiid,
        "ToTraderID": b[0],
        "ToTraderName": $('#txtOtherBuyerNameEN').val(),
        "ToTraderName_HI": $('#txtOtherBuyerNameHI').val()
    }
}),
    type: 'POST',
    contentType: 'application/json',
    dataType: 'json'              
});

Here:

$('[Id$="lblAuctionDateVal"]').text() = "20/8/2013 14:52:49" 

And my data type for this field is timestamp without time zone. How to convert this string to timestamp without time zone data type?

Answers


String representation of a timestamp (= timestamp without time zone) depends on your locale settings. Therefore, to avoid ambiguities leading to data erros or Postgres coughing up an exception, you have two options:

1.) Use ISO 8601 format, which works the same with any locale or DateStyle setting:

'2013-08-20 14:52:49'

You may still have to cast the string explicitly where the data type is no known a priori, depending on the use case:

'2013-08-20 14:52:49'::timestamp

2.) Convert your string to timestamp using to_timestamp() with a matching template pattern:

to_timestamp('20/8/2013 14:52:49', 'DD/MM/YYYY hh24:mi:ss')

To convert a string into a timestamp without timezone, for Postgresql, I use the above

SELECT to_timestamp('23-11-1986 09:30:00', 'DD-MM-YYYY hh24:mi:ss')::timestamp without time zone;

Need Your Help

Where does the ssh client in git bash store it's known_hosts file on windows?

git ssh git-bash

I'm running a git bash on windows 7, and would like to remove a few hosts from the known_hosts file.