Top 10 keyboard shortcuts everyone should know

 Using keyboard shortcuts can greatly increase your productivity, reduce repetitive strain, and help keep you focused. For example, to copy text, you can highlight text and press the Ctrl+C shortcut. The shortcut is faster than moving your hands from the keyboard, highlighting with the mouse, right-clicking, selecting copy, and returning to the keyboard.

Below are the top 10 keyboard shortcuts we recommend everyone memorize and use.

Ctrl+C or Ctrl+Insert and Ctrl+X

Both Ctrl+C and Ctrl+Insert will copy highlighted text or a selected item. If you want to cut an item instead of copying it, press Ctrl+X. This action removes the text or item and stores it in the clipboard, rather than copying it to the clipboard.

Apple computer users can substitute the Ctrl key for the Command on their computers. For example, pressing Command+C copies highlighted text.

Ctrl+V or Shift+Insert

Both the Ctrl+V and Shift+Insert will paste the text or object that's stored in the clipboard.

On Apple computers, use Command+V instead.

Practice

Use the above text input fields to highlight the "Cut or copy this text" text and press either Ctrl+C to copy or Ctrl+X to cut the text. Once cut, move to the next field and press Ctrl+V or Shift+Insert to paste the text. 

Ctrl+Z and Ctrl+Y

Pressing Ctrl+Z will undo any change. For example, if you cut text, pressing this key combination will undo the cut. These shortcuts can also be pressed multiple times to undo or redo multiple changes. Pressing Ctrl+Y would redo the undo.

On Apple computers, use Command+Z and Command+Y to undo and redo.

Use the above text input field to highlight some or all the text and then press Ctrl+X to cut the text. Once the text has disappeared, press the Ctrl+Z to undo the cut.

Tip

If you did the first example as well (cut and paste text) and you continue to press Ctrl+Z, it will undo that change.

Ctrl+F and Ctrl+G

Pressing Ctrl+F opens the Find field, which allows you to search the text currently displayed in any program that supports it. For example, Ctrl+F can be used in your Internet browser to find text on the current page. Press Ctrl+F now to open the Find in your browser and search for "shortcut" to display each time shortcut is mentioned on this page.

On Apple computers, use Command+F to find.

Ctrl+G may be used to repeat a search (from using Ctrl+F) in a document or on a web page.

Alt+Tab or Ctrl+Tab

Pressing Alt+Tab switches between open programs moving forward. For example, if you have your browser window open and other programs running in the background, press and hold Alt, then press the Tab key to cycle through each open program.

On Apple computers, instead of using the Alt key use the Command (Cmd) key. For example, Command+Tab to switch between open programs.

Bonus Tip

Press Ctrl+Tab to switch between tabs in a program. For example, if you have multiple tabs open in your Internet browser, press Ctrl+Tab to switch between them.

Bonus Tip

Adding the Shift key to Alt+Tab or Ctrl+Tab moves backward. For example, if you are pressing Alt+Tab and pass the program you want to use, press Alt+Shift+Tab to move back to that program.

Bonus Tip

Windows Vista, 7, 8, and 10 users can also press the Windows key+Tab to switch through open programs in a full screenshot of the window.

Ctrl+Backspace and Ctrl+Left or Right arrow

Note

The following shortcuts are for PC users only and do not work on Apple computers.

Pressing Ctrl+Backspace deletes a full word at a time instead of a single character.

Holding down the Ctrl while pressing the left or right arrow moves the cursor one word at a time instead of one character at a time. If you want to highlight one word at a time, hold down Ctrl+Shift, then press the left or right arrow key. Your highlighted selection moves one word at a time in that direction.

Ctrl+S

While working on a document or another file in almost every program, pressing Ctrl+S saves that file. Use this shortcut key frequently when working on anything important in case of an error, lost power, or any other issues causing you to lose work since the last save.

On Apple computers, use Command+S to save a file.

Ctrl+Home or Ctrl+End

Ctrl+Home moves the cursor to the beginning of the document, and Ctrl+End moves the cursor to the end of a document. These shortcuts work with most documents, and web pages.

On Apple computers, use the Command+Up arrow to get to the beginning or Command+Down arrow to get to the end of a document or text.

Ctrl+P

Ctrl+P is used to open a print preview of the page or document currently being viewed. For example, press Ctrl+P now to view a print preview of this page.

On Apple computers, use Command+P to open the print preview.

Page Up, Spacebar, and Page Down

As you may have guessed, pressing either the Pg Up or Pg Dn key moves to the next or previous page. When browsing the Internet, pressing the spacebar moves the scrollbar down a page. Similarly, Shift+spacebar moves the scrollbar up one page.

SQL Convert Date to YYYYMMDD

 

Create a Test Table

For this step we will create a test table: dbo.TestDate and load it with sample data.  Here is the T-SQL syntax:

Use Tempdb;

CREATE TABLE [dbo].[TestDate] (
   [ID] [int] IDENTITY(1,1) NOT NULL,
   [MyDate] [date]  NULL, -- date columm
   [CharDate] [char](8) NULL, -- date columm
   [MyDateTime] [datetime] NULL -- date columm
) ON [PRIMARY];
GO

 Load Sample Test Data

For this limited example we will only load 20 rows of test data. For the data load to convert the date to 'yyyymmdd' format, I will use CONVERT(CHAR(8), TheDate, 112). Format 112 is the ISO standard for yyyymmdd.

SET NOCOUNT ON;

DECLARE @SetDateTime DATETIME = '2020-01-01 14:04:03.230'; -- current date

INSERT INTO [dbo].[TestDate]
           ([MyDate],[CharDate],[MyDateTime])
SELECT CAST(Convert(CHAR(8),@SetDateTime,112) as DATETIME), Convert(CHAR(8),@SetDateTime,112), CAST(Convert(CHAR(8),@SetDateTime,112) as DATETIME);

INSERT INTO [dbo].[TestDate]
           ([MyDate],[CharDate],[MyDateTime])
SELECT @SetDateTime, Convert(CHAR(8),@SetDateTime,112), @SetDateTime
GO

INSERT INTO [dbo].[TestDate] ([MyDate] ,[CharDate], [MyDateTime])
SELECT top 1 [MyDateTime]+1, Convert(CHAR(8),[MyDateTime]+1,112), [MyDateTime]+1
FROM [dbo].[TestDate]
ORDER BY 1 desc 
GO 20  --load 20 days of dates

Results: Example SQL Server dates loaded.

Results of Sample DateTime Table.

Convert Dates to Char 'yyyymmdd'

Next, converting a DATE and DATETIME datatype to character 8 'yyyymmdd' output using CONVERT and FORMAT functions.

--A. CONVERT use style = 112 to CHAR 8 or NCAHR 8
SELECT CONVERT(CHAR(8),[MyDate],112) as 'MyDate',CONVERT(CHAR(8),[MyDateTime],112) as 'MyDateTime'
FROM [dbo].[TestDate];
 
--B. NCHAR(8)
SELECT CONVERT(NCHAR(8),[MyDate],112) as 'MyDate',CONVERT(NCHAR(8),[MyDateTime],112) as 'MyDateTime'
FROM [dbo].[TestDate];
 
--C. FORMAT Function (new in SQL 2012) use format = yyyyMMdd returning the results as nvarchar.
SELECT FORMAT([MyDate],'yyyyMMdd') as 'MyDate', FORMAT([MyDateTime],'yyyyMMdd')  as 'MyDateTime'
FROM [dbo].[TestDate]; 

Results: The results of the 3 queries all show the conversion to 'yyyymmdd' regardless of the format or the conversion method. The results below were reduced to 3 rows each for the demo.

Convert Dates to Char.

Convert Char 'yyyymmdd' back to Date data types in SQL Server

Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT.

--A. Cast and Convert datatype DATE:
SELECT [CharDate],
      CAST([CharDate] AS DATE) as 'Date-CAST',
      CONVERT(DATE,[CharDate]) as 'Date-CONVERT'
FROM [dbo].[TestDate];
 
--B. Cast and Convert datatype DATETIME:
SELECT [CharDate],
      CAST([CharDate] AS DATETIME) as 'DateTime-CAST',
      CONVERT(DATETIME,[CharDate]) as 'DateTime-CONVERT'
FROM [dbo].[TestDate];

Results: Below shows the results of converting CHAR 'yyyymmdd' to a DATE and DATETIME data types! SQL does this gracefully.

Convert Char to Dates.

Filtering Dates by Char 'yyyymmdd' and the Gotcha

Using Character 'yyyymmdd' as a filter in the WHERE clause against date datatypes.

-- Test 'YYYYMMDD' filter against Date datatypes

--A. DATE datatype
SELECT [MyDate]
FROM [dbo].[TestDate]
WHERE [MyDate] = '20200101'

--B.  DATETIME datatype
SELECT [MyDateTime]
FROM [dbo].[TestDate]
WHERE [MyDateTime] = '20200101' --implicit conversion to datetime Midnight!;

Results: Note the difference in the 2 result sets. When filtering against a DATETIME datatype, SQL implicitly converts the Character and appends a Midnight timestamp. Any rows with MyDateTime value other than midnight are excluded, i.e. 2020-01-01 14:04:03.230. This is the 'Gotcha'!

Filter and Gotcha

How to use Char 'yyyymmdd' filter against Datetime datatype to adjust for the Gotcha

When using the 'yyyymmdd' in the filter against DateTime datatype you must account for the timestamp part of the datatype!

--A. Use Greater Than and Equal and Less Than to get all dates with a Char 'yyyymmdd' Filter:
SELECT  *
FROM [dbo].[TestDate]
WHERE [MyDateTime] >= '20200101' 
  AND [MyDateTime] < '20200102' --implicit conversion to datetime Midnight!;

What happens if we filter with yyyyymmdd as an Integer value?

--A. Test yyyymmdd filter against Date datatype using and integer 
SELECT  *
FROM [dbo].[TestDate]
WHERE [MyDate] = 20200101;

Results: We can't do this because it results in an error!

Error Int Filter

Alternative Formats

Last, I will share examples of alternative formats for returning dates. Also, I will show how robust SQL is at converting the other formats when used in a where clause.

--A. Alternative formats that returns Year Month Day mixing Date and Datetime formats using CONVERT:
SELECT CONVERT(CHAR(10),[MyDate],120) as 'MyDate_w_Dash',
       CONVERT(CHAR(10),[MyDateTime],111) as 'MyDateTime_w_Slash',
       CONVERT(CHAR(10),[MyDateTime],102) as 'MyDateTime_w_Dot'
FROM [dbo].[TestDate];

--B. Alternative formates that returs Year Month Day mixing Date and Datetime formats using FORMAT:
SELECT FORMAT([MyDate],'yyyy-MM-dd') as 'MyDate_w_Dash',
       FORMAT([MyDate],'yyyy/MM/dd') as 'MyDate_w_Slash',
       FORMAT([MyDateTime],'yyyy.MM.dd') as 'MyDateTime_w_Dot'
FROM [dbo].[TestDate];
 
--C. Note using Year, month, day in the where clause that SQL server will recognize different delimiters: dash, slash, dot or no delimiter as shown above.
SELECT *
FROM [dbo].[TestDate]
WHERE [MyDateTime] = '2020.01.01' --or '2020/01/01' or '2020-01-01' or '20200101'
;

Results: Review the 3 result sets from the queries! Note the different date delimiters and the ability to use different delimited dates as filters.

Alternate Formats.

Wrap Up

I hope you enjoyed this exercise on year, month, day date formats and can see the flexibility that SQL Server has handling dates. Other ways to take advantage of the Year Month Day short format, might include concatenating a date to a file name or naming a monthly billing batch. I have also seen the use of Char(6) YYYYMM to denote financial monthly periods. Please comment on other ways you may have used the yyyymmdd date format!