Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Macro : How can I get the timestamp in "yyyy-MM-dd hh:mm:ss" format?

Tags:

excel

vba

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?

like image 349
Parth Bhatt Avatar asked Mar 28 '11 09:03

Parth Bhatt


People also ask

How do I convert timestamps to mm/dd/yyyy in Excel?

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.

How do I format a date in Excel macro?

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.

How do I use CDate in Excel VBA?

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.


1 Answers

Try with: format(now(), "yyyy-MM-dd hh:mm:ss")

like image 124
Mohamed Saligh Avatar answered Oct 05 '22 00:10

Mohamed Saligh