Column that will dysplay current date in grocery_crud CodeIgniter - codeigniter-2

In grocery_crud and Code Igniter in table Employees I have column today(dd/mm/yyyy). How to set column to display current date. Please help me.

With MySQL you can't do this with a Date but with a Timestamp column, and you add 'CURRENT_TIMESTAMP' as the default value.
That said as of MySQL version 5.6.5 you can do it with :
CREATE TABLE foo (
`creation_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP
)
as explained here :
https://stackoverflow.com/a/10603198/1226118

Related

Create ExpiryDate during table definition in Oracle

I'm trying to create a table named MEMBER. The datatype for REGISTERDATE is DATE and the default value is SYSDATE. There is another column named EXPIRYDATE, datatype is DATE and the default value is 1 year after SYSDATE. So how am I going to create for the column of EXPIRYDATE when creating the table definition?
I tried REGISTERDATE DATE DEFAULT SYSDATE,
EXPIRYDATE DATE + 365,
It showed error..
You're so close, you're just missing the default keyword and sysdate after expirydate date
-
create table MEMBER (
REGISTERDATE date default sysdate,
expirydate date default sysdate+365
)
test:
insert into MEMBER(REGISTERDATE) values (sysdate)
output:
Not all years have 365 days; on average, only 3 out of 4. But you can literally define an expression that expresses "1 year after":
create table member (
id number(*,0) not null primary key,
registerdate date default sysdate,
expirydate date default sysdate + interval '1' year
);
Remember that Oracle won't use the default value if you provide your own, even if it's null. You need to complete omit the field from the INSERT INTO statement.
Demo

how to set column default value like current_timestamp in clickhouse?

does anyone know how to use a default value like current_timestamp in mysql when creating a clickhouse table? The now() udf is dynamic, instead of the time the row inserted, it is always the current time, it changes when select.
Here is my table:
CREATE TABLE default.test2 (
`num` UInt32,
`dt` String,
`__inserted_time` DateTime DEFAULT now()
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/test2', '{replica}')
PARTITION BY dt
ORDER BY dt
SETTINGS index_granularity = 8192
I want the __inserted_time column value generated automatically thus I don't have to specify it in the insert into test2 (num,dt) values (1,'20191010')
my mistake, DEFAULT now() actually works

Create a date column in oracle with default time value

I'm trying to create the following table:
CREATE TABLE helpToolStatsTest (
customer nvarchar2(25),
data nvarchar2(7),
myDate Date NOT NULL DEFAULT CURRENT_DATE()
)
but I'm getting this error:
ORA-00907: missing right parenthesis
According to the documentation:
CREATE TABLE helpToolStatsTest (
customer nvarchar2(25),
data nvarchar2(7),
myDate Date DEFAULT CURRENT_DATE NOT NULL
)

How to automatically get the current date and time in a column using HIVE

Hey I have two columns in my HIVE table :
For example :-
c1 : name
c2 : age
Now while creating a table I want to declare two more columns which automatically give me the current date and time when the row is loaded.
eg: John 24 26/08/2015 11:15
How can this be done?
Hive currently does not support the feature to add a default value to any column definition while creating a table. Please refer to the link for complete hive create table syntax:
Hive Create Table specification
Alternative work around for this issue would be to temporarily load data into temporary table and use the insert overwrite table statement to add the current date and time into the main table.
Below example may help:
1. Create a temporary table
create table EmpInfoTmp(name string, age int);
2. Insert data using a file or existing table into the EmpInfoTmp table:
name|age Alan|28 Sue|32 Martha|26
3. Create a table which will contain your final data:
create table EmpInfo(name string, age tinyint, createDate string, createTime string);
4. Insert data from the temporary table and with that also add the columns with default value as current date and time:
insert overwrite table empinfo select name, age, FROM_UNIXTIME( UNIX_TIMESTAMP(), 'dd/MM/YYYY' ), FROM_UNIXTIME( UNIX_TIMESTAMP(), 'HH:mm' ) from empinfofromfile;
5. End result would be like this:
name|age|createdate|createtime Alan|28|26/08/2015|03:56 Martha|26|26/08/2015|03:56 Sue|32|26/08/2015|03:56
Please note that the creation date and time values will be entered accurately by adding the data to your final table as and when it comes into the temp table.
Note: You can't set more then 1 column as CURRENT_TIMESTAMP.
Here this way, You cant set CURRENT_TIMESTAMP in one column
SQL:
CREATE TABLE IF NOT EXISTS `hive` (
`id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`age` int(11) DEFAULT '0',
`datecreated` timestamp NULL DEFAULT CURRENT_TIMESTAMP
);
Hey i found a way to do it using shell script.
Heres how :
echo "$(date +"%Y-%m-%d-%T") $(wc -l /home/hive/landing/$line ) $dir " >> /home/hive/recon/fileinfo.txt
Here i get the date without spaces. In the end I upload the textfile to my hive table.

Oracle Default Column Value Calculated Date

I am trying to create a table that has a default value for a date that is sysdate - 2 in oracle
Oracle seems to be fine with sysdate as the default but not sysdate - 2. Is this possible?
You need to specify the DEFAULT value in brackets:
Create the table:
CREATE TABLE order_status (
order_id NUMBER,
last_modified DATE DEFAULT (SYSDATE - 2)
);
Insert a record to test the default:
INSERT INTO order_status
(order_id)
VALUES
(1);
Select the data from the table to confirm the default worked (Current date 14/11/2011):
SELECT *
FROM order_status;
ORDER_ID LAST_MODIFIED
1 12/11/2011
DB Version 10g.
Hope it helps...

Resources