I am using DateTime.Now
in my Excel Macro to show the current timestamp.
It shows timestamp in "dd-MM-yyyy hh:mm:ss" format.
Instead, how can I get the timestamp in "yyyy-MM-dd hh:mm:ss" format?
Select a blank cell next to your date, for instance. I1, and type this formula =TEXT(G1, "yyyy-mm-dd"), and press Enter key, then drag AutoFill handle over the cells needed this formula. Now all dates are converted to texts and shown as yyyy-mm-dd format.
Click on Insert tab > select Module. Step 2: Write the subprocedure for VBA Format Date or choose anything to define the module. Step 3: Choose the range cell first as A1. Step 4: Then use the Number Format function as shown below.
Step 1: Write the subprocedure of VBA CDate as shown below. Step 2: Now we will declare 3-4 different variables of Data type Date. Let's declare the first variable as Date1 and give it the data type as Date as shown below. Step 3: Now assign any number which we want to convert it in Date format.
Try with: format(now(), "yyyy-MM-dd hh:mm:ss")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With