[Tex/LaTex] hfill alignment doesn´t work

horizontal alignment

I used the code below to format some information but the last line before the red line is not right aligned. I can`t find the problem in the code. Any suggestion? Thanks.

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage{color}
\usepackage[T1]{fontenc}

\setlength{\parindent}{0em}

\begin{document}
\begin{samepage}
    {\color{blue}\hrule height 2pt}
    \vspace{.1\baselineskip}
    {\Large Some important text}
    \hfill
    {\large \textit{And more}} \\ 
    {\small More some text}
    \hfill \textit{Important person:}~Me \\[.3\baselineskip]
    {Year:~2018, Volume:~1, Nr.:~1}
    \hfill
    Date 1: YYYY-MM-DD\\ 
    {Classification:~A}
    \hspace{\fill}
    Date 2: YYYY-MM-DD
    \vspace{.3\baselineskip}
    {\color{red}\hrule height 2pt}
    \end{samepage}
\end{document} 

Best Answer

You have to protect end of lines in a few places, otherwise a space might appear there.

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage{color}
\usepackage[T1]{fontenc}

\setlength{\parindent}{0em}

\begin{document}
\begin{samepage}
    {\color{blue}\hrule height 2pt}
    \vspace{.1\baselineskip}
    {\Large Some important text}
    \hfill
    {\large \textit{And more}} \\ 
    {\small More some text}
    \hfill \textit{Important person:}~Me \\[.3\baselineskip]
    {Year:~2018, Volume:~1, Nr.:~1}
    \hfill
    Date 1: YYYY-MM-DD\\ 
    {Classification:~A}
    \hspace{\fill}
    Date 2: YYYY-MM-DD% <- Here
    \vspace{.3\baselineskip}% <- Here
    {\color{red}\hrule height 2pt}% <- Here (this one isn't necessary, actually)
    \end{samepage}
\end{document}

Edit: A comment at the end of the line? Seriously?

This is something that everyone already had problems with (the "everyone" link is the best :P).

What happens here is that (in normal situations) TeX interprets a line break as a space character, so when you type:

abc
def

the result is the same as if you had typed:

abc def

(notice the space after c). But when you type:

abc%
def

TeX ignores everything that comes after the %, and this includes the line break, so it is essentially the same as:

abcdef

And that's why you had a space after the DD in your code.

When you have the time, I suggest you read koleygr's answer here and if you want a more lengthy explanation, my answer here.