create database tanggal
use tanggal
create table tbltgl(tgl1 datetime,tgl2 datetime)
insert into tbltgl(tgl1,tgl2) values('12/12/2010','01/01/2011')
insert into tbltgl(tgl1,tgl2) values('12/25/2010','01/03/2011')
insert into tbltgl(tgl1,tgl2) values('12/30/2010','01/05/2011')
insert into tbltgl(tgl1,tgl2) values('01/02/2010','01/04/2011')
select*from tbltgl
TAMPILAN :
--Fungsi-fungsi Tanggal
select tgl1,YEAR(tgl1) as Tahun from tbltgl
TAMPILAN :
select tgl1,MONTH(tgl1) as Bulan from tbltgl
TAMPILAN :
select tgl1,DAY(tgl1) as Tangal from tbltgl
TAMPILAN :
---Tampilan Tanggal,Bulan dan Tahun seperti tampilan di bawah ini ?
select DAY(tgl1) as Tanggal, MONTH(tgl1) as Bulan,
YEAR(tgl1) as Tahun from tbltgl
TAMPILAN :
select GETDATE() as "tgl dan jam saat ini / system"
TAMPILAN :
select DATEDIFF(DAY,tgl1,tgl2) as "Selisih hari" from tbltgl
TAMPILAN :
select DATEDIFF(MONTH,tgl1,tgl2) as "selisih bulan" from tbltgl
TAMPILAN :
select DATEDIFF(year,tgl1,tgl2) as "selisih tahun" from tbltgl
TAMPILAN :
--Tambahkan Kolom/Field Tanggal lahir,
--dan isinya Anda sesuaikan Sendiri !
alter table tbltgl add [Tanggal Lahir] datetime
select * from tbltgl
update tbltgl set [tanggal lahir]='10/10/1982' where tgl1='12/12/2010'
update tbltgl set [tanggal lahir]='12/11/1987' where tgl1='12/25/2010'
update tbltgl set [tanggal lahir]='12/10/1988' where tgl1='12/30/2010'
update tbltgl set [tanggal lahir]='12/12/1986' where tgl1='01/07/2010'
tampilan :
--tampilkan tanggal lahir dan usia seperti di bawah ini ???
select [tanggal lahir],
year (getdate())-year([tanggal lahir]) as usia from tbltgl
TAMPILAN :










Tidak ada komentar:
Posting Komentar