Saturday, April 19, 2014

16 Fungsi VBA Untuk Tanggal Dan Waktu

www.AstroDigi.comAstroDigi.com | Sabtu, 19 Apr 2014 | Dalam pekerjaan membuat aplikasi seringkali kita membutuhkan fungsi program yang mampu mengolah tanggal dan waktu. Seperti misalnya menghitung perbedaan tanggal, mencari bulan yang sekarang, menambahkan 3 bulan dari waktu yang sekarang (biasanya untuk menghitung jatuh tempo), mencatat hari (Senin, Selasa, Rabu, dst).

Beruntunglah VBA mempunyai fungsi fungsi yang dapat dipergunakan untuk pengelolaan tanggak dan waktu. Berikut ini adalah fungsi tanggal dan waktu yang sering dipergunakan:

1. DATESERIAL
Mengisi/menginput tanggal kedalam suatu variabel
Format:
DateSerial («tahun», «bulan», «tanggal»)

Contoh:

Dim tgl As Date
tgl = DateSerial(14,11,5)

hasilnya > tgl = 5/11/2014

2. TIMESERIAL
Mengisi/menginput waktu kedalam suatu variabel
Format:
TimeSerial («jam», «menit», «detik»)

Contoh:

Dim wkt As Date
wkt = TimeSerial(18, 21, 52)

hasilnya > wkt = 18:21:52

3. DATEDIFF
Menghitung selisih tanggal atau selisih waktu, diperlukan interval untuk menyatakan object yang dihitung selisihnya
Format:
DateDiff («interval», «tanggal1», «tanggal2»)
DateDiff («interval», «waktu1», «waktu2»)

catatan interval:
tahun = yyyy
bulan = m
tanggal = d

jam = h
menit = n
detik = s

Contoh:

Dim tgl1, tgl2,tgl3 As Date
tgl1 = DateSerial(11,9,5)
tgl2 = DateSerial(14,11,5)

tgl3 = DateDiff("yyyy", tgl1, tgl2)

hasilnya > tgl3 = 3

4. WEEKDAY
Mencatat hari sesuai dengan tanggal, dimana hari dinyatakan dengan angka
1 = Minggu
2 = Senin
3 = Selasa
4 = Rabu
5 = Kamis
6 = Jumat
7 = Sabtu

Format:
Weekday («tanggal»)

Contoh:

Dim tgl1 As Date
Dim tgl2 As Integer

tgl1 = DateSerial(14, 4, 19)
tgl2 = Weekday(tgl1)

hasilnya > tgl2 = 7

5. DAY
Menampilkan tanggal
Format:
Day(«tanggal»)

Contoh:
tgl = Day("1/31/99")

hasilnya > tgl = 31

6. MONTH
Menampilkan bulan
Format:
Month(«tanggal»)

Contoh:
tgl = Month("1/31/99")

hasilnya > tgl = 1

7. YEAR
Menampilkan tahun
Format:
Year(«tanggal»)

Contoh:
tgl = Year("1/31/99")

hasilnya > tgl = 99

8. HOUR
Menampilkan jam
Format:
Hour(«waktu»)

Contoh:
wkt = Hour("8:21:53")

hasilnya > wkt = 8

9. MINUTE
Menampilkan menit
Format:
Minute(«waktu»)

Contoh:
wkt = Minute("8:21:53")

hasilnya > wkt = 21

10. SECOND
Menampilkan menit
Format:
Second(«waktu»)

Contoh:
wkt = Second("8:21:53")

hasilnya > wkt = 53

11. DATE
Menampilkan tanggal saat ini

Contoh:
tgl = Date

hasilnya > tgl = tanggal saat ini, misalnya 19/04/2014


12. TIME
Menampilkan waktu saat ini

Contoh:
wkt = Time

hasilnya > tgl = waktu saat ini, misalnya 8:40:53

13. NOW
Menampilkan tanggal dan waktu saat ini

Contoh:
x = Now

hasilnya > x = tanggal dan waktu saat ini, misalnya 19/04/2014 8:40:53

14. DATEADD
Menjumlahkan tanggal atau waktu, diperlukan interval untuk menyatakan object yang dijumlahkan
Format:
DateAdd («interval», «angka», «tanggal»)

catatan interval:
tahun = yyyy
bulan = m
tanggal = d

jam = h
menit = n
detik = s

Contoh:

Dim tgl As Date
tgl = DateSerial(11,9,5)
tgl = DateAdd("yyyy", 7, tgl)

hasilnya > tgl = 05/09/2018

Contoh 2:

Dim wkt As Date
wkt = TimeSerial(8,5,26)
wkt = DateAdd("n", 25, wkt)

hasilnya > wkt = 8:30:26

15. DATEVALUE
Merubah text menjadi tanggal
Format:
DateValue («text»)

Contoh:
tgl = DateValue("5/9/2014") 

hasilnya > tgl = 05/09/2014

16. TIMEVALUE
Merubah text menjadi tanggal
Format:
TimeValue («text»)

Contoh:
wkt = TimeValue("9:0:26") 

hasilnya > wkt = 9:00:26

 www.AstroDigi.com (Nino Guevara Ruwano)

Comments :

11 comments to “16 Fungsi VBA Untuk Tanggal Dan Waktu”

ninest123 07.31
true religion jeans, oakley sunglasses, louboutin, michael kors outlet, michael kors outlet, coach outlet, longchamp outlet, tiffany jewelry, christian louboutin outlet, michael kors, kate spade outlet, prada handbags, ray ban sunglasses, gucci outlet, tiffany and co, replica watches, michael kors outlet, coach outlet, nike air max, polo ralph lauren outlet, louboutin shoes, ray ban sunglasses, tory burch outlet, michael kors outlet, jordan shoes, nike air max, oakley sunglasses, chanel handbags, coach purses, kate spade handbags, nike free, coach factory outlet, burberry, longchamp outlet, burberry outlet online, nike outlet, prada outlet, oakley sunglasses, polo ralph lauren outlet, longchamp, michael kors outlet, louboutin outlet

Unknown said...
on 

true religion outlet, mulberry, lacoste pas cher, true religion jeans, nike air max, new balance pas cher, abercrombie and fitch, lululemon, hermes, nike blazer, longchamp pas cher, air force, vans pas cher, michael kors, nike free run uk, north face, sac guess, nike air max, air jordan pas cher, burberry, converse pas cher, north face, louboutin pas cher, nike air max, nike free, vanessa bruno, ralph lauren pas cher, sac longchamp, michael kors, ralph lauren uk, ray ban uk, air max, hollister, oakley pas cher, michael kors, hogan, tn pas cher, hollister pas cher, ray ban pas cher, nike roshe run, true religion jeans, timberland

Unknown said...
on 

wedding dresses, soccer jerseys, nike roshe, abercrombie and fitch, iphone 6 cases, ferragamo shoes, reebok shoes, soccer shoes, ghd, asics running shoes, nike huarache, lululemon, vans shoes, instyler, nike roshe, oakley, insanity workout, p90x workout, mcm handbags, north face outlet, beats by dre, celine handbags, bottega veneta, baseball bats, north face outlet, longchamp, giuseppe zanotti, hollister, valentino shoes, new balance, nfl jerseys, hollister, jimmy choo shoes, babyliss, herve leger, mac cosmetics, birkin bag, timberland boots, chi flat iron, nike trainers, mont blanc, nike air max

Unknown said...
on 

swarovski, replica watches, toms shoes, ugg boots, supra shoes, marc jacobs, montre pas cher, links of london, thomas sabo, vans, hollister, ugg pas cher, ugg,ugg australia,ugg italia, nike air max, ray ban, ugg boots uk, ugg boots, ugg,uggs,uggs canada, karen millen, gucci, bottes ugg, lancel, uggs on sale, ralph lauren, hollister, converse, wedding dresses, pandora charms, louboutin, juicy couture outlet, converse outlet, juicy couture outlet, pandora charms, swarovski crystal, ugg boots, coach outlet, pandora jewelry, ugg boots
ninest123 07.31

Unknown said...
on 

toms outlet
michael kors handbags
michael kors outlet
ed hardy outlet
michael kors outlet
yeezy boost 350 white
mont blanc pens outlet
cheap nfl jerseys
christian louboutin shoes
nike trainers

raybanoutlet001 said...
on 

jordan shoes
ray ban glasses
discount oakley sunglasses
adidas sneakers
adidas store
michael kors outlet canada
ugg boots
nfl jerseys wholesale
michael kors outlet store
coach outlet online
20161114yuanyuan

John said...
on 

chicago bulls jersey
instyler max 2
nike air huarache
raiders jerseys
michael kors
toms shoes
versace
birkenstock sandals
oklahoma city thunder jerseys
true religion jeans

Unknown said...
on 

adidas trainers
fitflops
boston celtics jerseys
fit flops
true religion outlet
red bottoms shoes
coach factory outlet
christian louboutin
cheap ray ban sunglasses
nike blazer low
20170324huazhen

Unknown said...
on 

20180420 xiaoou
christian louboutin shoes
polo ralph lauren
polo ralph lauren
coach outlet online
coach factory outlet
christian louboutin sale
true religion jeans
louis vuitton outlet store
coach outlet
uggs outlet online

Unknown said...
on 

20180612xiaoke
tory burch outlet store
kate spade outlet store
manolo blahnik
coach factory outlet
coach factory outlet
canada goose outlet online
nike nba jerseys
polo pas cher
true religion jeans sale
jordan shoes

Unknown said...
on 

lebron james shoes
air jordan
balenciaga sneakers
louboutin shoes
nike air vapormax
coach factory outlet
jordan shoes
michael kors handbags sale
coach outlet
yeezy shoes

yanmaneee said...
on 

Post a Comment