I started working on arduino very recently. I am trying to design a button. i have to attach a timer to the button. this is because i need the duration of my button press so that i can use the same button for short and long presses. How do i do it?

When the button is pressed make a note of the time.
Wait till button is released.
Subtract current (release) time from pressed time to see how long button was pressed and act accordingly.

The below example is not complete but should give you an idea. If other stuff needs to still happen while the button is pressed then this code is not suitable.

const long debounceDelay = 30;                // Button debounce time
const long buttonDelay = 3000;                // Button hold time to go into adjust mode (3 seconds)

void loop(){
  if (checkButton(encButton) == HIGH){
    unsigned long downTime = millis();        // Get current timer
    while (checkButton(encButton) == HIGH){};         // Wait for button to be released
    if ((millis() - downTime) < buttonDelay){
      // Short Press                          // Call Date Display Routine
      // Long Press                           // Call Adjust Routine
// Button = pin number to read
int checkButton(int Button){
  if (digitalRead(Button) == HIGH){           // If button pressed then wait a bit to allow for debounce
    return digitalRead(Button);               // Return button state
  else {                                      // Button not pressed so no need to wait for bebounce
    return LOW;

Thank you so much. I had been trying with the pulseIn function as well. wouldn't that do ?