TIMESTAMP without time zone is displayed at the same format as DATETIME,and its format is
'YYYY-MM-DD HH:MM:SS'
.
TIMESTAMP with time zone is displayed datetime and time zone ,and its is 'YYYY-MM-DD HH:MM:SS ZZZ'
.
How to create timestamp in Postgre Sql ?
1.With time zone
CREATE TABLE MyProject."Employee"
(
IDX bigint NOT NULL,
Name character varying(64) NOT NULL,
RegisterDate timestamp with time zone NOT NULL,
CONSTRAINT Employee_pkey PRIMARY KEY (idx)
)
ALTER TABLE MyProject."Employee"OWNER TO postgres;
2.Without time zone
CREATE TABLE MyProject."Employee"
(
IDX bigint NOT NULL,
Name character varying(64) NOT NULL,
RegisterDate timestamp without time zone NOT NULL,
CONSTRAINT Employee_pkey PRIMARY KEY (idx)
)
ALTER TABLE MyProject."Employee"OWNER TO postgres;
How to insert timestamp column in Postgre Sql(database) with C#.NET 2005?
1.With time zone
NpgsqlConnection NpgCon = new NpgsqlConnection(String.Format("Server={0};Port={1};" +
"User Id={2};Password={3};Database= postgres;",
txtServerName.Text, txtPort.Text, txtUserID.Text, txtPassword.Text););
NpgsqlConnection NpgCon = new NpgsqlConnection(NpgCon );
try
{
NpgCon.Open();
string txtCommand;
txtCommand="INSERT INTO MyProject."Employee"(IDX , Name, RegisterDate )VALUES (" + txtEmpID.Text + ",'" + txtEmpName.Text + "','" + DTEnrollmentdate.Value.ToString("yyyy-MM-dd hh:mm:ss zzz") + "')";
NpgsqlCommand cmd = new NpgsqlCommand(txtCommand, NpgCon);
cmd.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
return;
}
finally
{
if (NpgCon.State == ConnectionState.Open)
NpgCon.Close();
}
2.Without time zone
NpgsqlConnection NpgCon = new NpgsqlConnection(String.Format("Server={0};Port={1};" +
"User Id={2};Password={3};Database= postgres;",
txtServerName.Text, txtPort.Text, txtUserID.Text, txtPassword.Text););
NpgsqlConnection NpgCon = new NpgsqlConnection(NpgCon );
try
{
NpgCon.Open();
string txtCommand;
txtCommand="INSERT INTO MyProject."Employee"(IDX , Name, RegisterDate )VALUES (" + txtEmpID.Text + ",'" + txtEmpName.Text + "','" + DTEnrollmentdate.Value.ToString("yyyy-MM-dd hh:mm:ss") + "')";
NpgsqlCommand cmd = new NpgsqlCommand(txtCommand, NpgCon);
cmd.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
return;
}
finally
{
if (NpgCon.State == ConnectionState.Open)
NpgCon.Close();
}
0 comments:
Post a Comment