peri hokiperihokiclarustologisticsrimashaop.compola taktis menang gates of olympus x1000 perihokipemain perihoki bongkar trik jepep starlight princess x1000perihoki beri panduan lengkap bermain mahjong ways 2 pgsofttips cara penghasil uang pgsoft mahjong ways 2 perihokimahjong wins 3 perihoki memberikan penggali terbesarfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76perihoki spin mahjong ways 2 pgsoft scatter hitam maxwinsimbol mahjong wins 3 yang sering muncul di awal perihokitrik gampang menang mahjong winscuan mahjong wins 3 tanpa hentipola spin taruhan kecil mahjong winsstrategi kunci scatter hitam beruntungacor total mahjong wayskemenangan maksimal mahjong wayskemenangan pria pekanbaru mahjong waysmahjong wins3 fenomena baru sumatera baratmenangkan mahjong dengan lincahmenembus batas keberuntungan mahjong waysmenjajal keberuntungan di mahjong wayspola gratis mahjong ways1scatter hitam senjata rahasia mahjong winsteknik spinning menguntungkan untuk scatter hitamanalisis rtp tertinggi mahjong winsfenomena scatter hitam mahjong winsibu rumah tangga dan keberuntungan mahjongkeseruan main mahjong wins3menang mahjong pengguna baru di sosial mediamenghargai setiap momen di mahjong waysserunya main mahjong di warung internetspin slow motion mancing scatterstrategi jitu maxwin mahjong waysstrategi jitu menang mahjong modal kecil jackpot besaranak kampung papua menggemparkan mahjongkeajaiban scatter hitam mahjong wayskeberhasilan joni mahjong winskejaiban mahjong ways di ujung jalanketua mahjong wins3 kehadiran kemenangan dimulai dari balimahjong kehadiran yang menguntungkanmahjong menggila adat88panduan kilat raih 108 jutatips memenangkan mahjongbarista kopi menang 110 juta spin mahjongdakota76 scatter hitam mahjong wins 3gagal cpns menang mahjong wins 3 rp120 jutakisah karyawan minimarket dapat thr lebih awal mahjong winskisah pelajar sma kuasai mahjong wins 3 inspirasi sekolahkisah penjaga parkir tanah abang motor baru mahjong winskisah sukses ibu rumah tangga bandung mahjong winsmahasiswa kkn beli iphone15 mahjong wins3 dakotamantan anak band influencer mahjong scatter hitampola rtp senin gates of olympus guru matematikaidola scatter hitam gampang meledakidola sensasi jackpotidola pola scatter hitamidola hasilkan jackpot dalam waktu singkatidola mahjong wins 3 bocortukang cuci motor menemukan keberuntungan di mahjong

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

Các hàm xử lý ngày tháng trong VBA (Date & Time)
MACRO
EXCEL OBJECT
VBA BASIC
VBA FORM
BÀI TẬP
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

Các hàm xử lý ngày tháng trong VBA (Date & Time)

Trong bài này mình sẽ giới thiệu những hàm xử lý ngày tháng trong VBA được sử dụng nhiều nhất. Với những hàm này bạn có thể lấy được các giá trị về thời gian và ngày tháng rất dễ dàng.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Và cũng giống như những ngôn ngữ khác, xoay quanh nội dung về xử lý ngày tháng / thời gian thì chủ yếu là cách tạo ngày tháng, tạo thời gian, cộng thời gian, lấy ngày giờ hiện tại, và những hàm bóc tách thời gian thành nhiều phần nhỏ.

Trước tiên chúng ta sẽ tìm hiểu về đối tượng Date nhé.

1. Đối tượng Date trong VBA

Date là đối tượng dùng để lưu trữ ngày tháng. Nó là một kiểu dữ liệu Object nên bạn có thể khai báo một biến kiểu Date.

Bài viết này được đăng tại [free tuts .net]

Ví dụ: Khai báo một biến kiểu Date và dùng hàm DateValue để khởi tạo giá trị cho biến đó. Cuối cùng dùng hàm Year để lấy ra năm của ngày.

Dim exampleDate As Date

exampleDate = DateValue("Jan 19, 2020")

MsgBox Year(exampleDate)

Kết quả:

year png

Tương tự, bạn có thể sử dụng hàm Month Day để lấy ngày tháng.

Month(exampleDate)
Day(exampleDate)

2. Hàm DateAdd trong VBA

Để thêm một số ngày vào một ngày thì ta sử dụng hàm DateAdd. Hàm DateAdd có ba đối số như sau:

  • Điền vào "d" cho đối số đầu tiên để thêm ngày, "m" để thêm tháng.
  • Điền vào 3 cho đối số thứ hai để thêm 3 ngày.
  • Đối số thứ ba đại diện cho ngày mà số ngày sẽ được thêm vào.
Dim firstDate As Date, secondDate As Date

firstDate = DateValue("Jan 19, 2020")
secondDate = DateAdd("d", 3, firstDate)

MsgBox secondDate

Kết quả biến secondDate đã được bổ sung thêm 3 ngày so với firstDate.

dateadd png

* Lưu ý: Bạn có thể đôi tham số đầu tiên từ d sang m để thêm vào số tháng thay vì số ngày. Riêng đối với năm thì không được.

3. Hàm Now: Lấy ngày tháng hiện tại

Để lấy ngày tháng hiện tại trên máy tính của bạn thì có thể sử dụng hàm Now.

MsgBox Now

Kết quả:

current date time png

* Lưu ý: Ngày tháng hiện tại nó trả về chính là ngày tháng trên máy tính mà bạn đang sử dụng nhé.

4. Các hàm Hour, Minute, Second

Ba hàm Hour, Minute Second dùng để lấy giờ, phút và giây.

Ví dụ:

' Giờ
MsgBox Hour(Now)

' Phút
MsgBox Minute(Now) 

' Giây
MsgBox Second(Now) 

5. Hàm TimeValue trong VBA

Nếu hàm DateValue dùng để tạo ra ngày tháng thì hàm TimeValue được dùng để tạo ra thời gian.

Hàm TimeValue chuyển đổi một chuỗi thành time serial number, đây là một số từ 0 đến 1.

Ví dụ: buổi trưa (nửa ngày) được biểu thị bằng 0,5.

MsgBox TimeValue("9:20:01 am")

Kết quả:

timevalue png

Bây giờ để thấy rõ rằng Excel xử lý thời gian nội bộ dưới dạng số từ 0 đến 1 thì hãy thêm các dòng mã sau:

Dim y As Double
y = TimeValue("09:20:01")
MsgBox y

time serial number png

Lý do là mình dùng kiểu dữ liệu Double để lưu trữ thời gian nên hàm TimeValue trả về một time series number.

Trên là tổng hợp những thao tác xử lý ngày tháng và thời gian trong VBA. Qua bài này bạn đã hiểu được một số hàm về Date time như: DateValue, TimeValue, Hour, Second, Minute, Year, Month, Date ... và nhiều hàm khác.

Cùng chuyên mục:

Cách chèn link ảnh vào Excel trên máy tính

Cách chèn link ảnh vào Excel trên máy tính

Ngoài ra, bài viết còn hướng dẫn cách chèn link ảnh trực tuyến hàng loạt…

Cách tách và gộp ô trong Excel

Cách tách và gộp ô trong Excel

Trong bảng tính Microsoft Excel, có thể sẽ có lúc các bạn cần tách ô…

Hàm MONTH() trong Excel

Hàm MONTH() trong Excel

Cách dùng hàm MONTH() trong Excel

Hàm YEAR () trong Excel

Hàm YEAR () trong Excel

Cách dùng hàm YEAR () trong Excel

Hàm HLOOKUP() trong Excel

Hàm HLOOKUP() trong Excel

Cách dùng hàm HLOOKUP() trong Excel

Hàm VLOOKUP() trong Excel

Hàm VLOOKUP() trong Excel

Cách dùng hàm VLOOKUP() trong Excel

Hàm LOOKUP() trong Excel

Hàm LOOKUP() trong Excel

Cách dùng hàm LOOKUP() trong Excel

Hàm ABS() trong Excel

Hàm ABS() trong Excel

Cách dùng hàm ABS() trong Excel

Hàm SUM() trong Excel

Hàm SUM() trong Excel

Cách dùng hàm SUM() trong Excel

Hàm SQRT() trong Excel

Hàm SQRT() trong Excel

Cách dùng hàm SQRT() trong Excel

Hàm MOD() trong Excel

Hàm MOD() trong Excel

Cách dùng hàm MOD() trong Excel

Hàm SUMIF() trong Excel

Hàm SUMIF() trong Excel

Cách dùng hàm SUMIF() trong Excel

Hàm SUBTOTAL() trong Excel

Hàm SUBTOTAL() trong Excel

Cách dùng hàm SUBTOTAL() trong Excel

Hàm ROUND() trong Excel

Hàm ROUND() trong Excel

Cách dùng hàm ROUND() trong Excel

Hàm SUMPRODUCT() trong Excel

Hàm SUMPRODUCT() trong Excel

Cách dùng hàm SUMPRODUCT() trong Excel

Hàm COUNT() trong Excel

Hàm COUNT() trong Excel

Cách dùng hàm COUNT() trong Excel

Hàm COUNTA() trong Excel

Hàm COUNTA() trong Excel

Cách dùng hàm COUNTA() trong Excel

Hàm COUNTBLANK() trong Excel

Hàm COUNTBLANK() trong Excel

Cách dùng hàm COUNTBLANK() trong Excel

Hàm MAX() trong Excel

Hàm MAX() trong Excel

Cách dùng hàm MAX() trong Excel

Hàm MIN() trong Excel

Hàm MIN() trong Excel

Cách dùng hàm MIN() trong Excel

Top