Need Help with DateTime Conversion in FlutterFlow

Actions & Logic

Hi everyone,

I'm currently facing an issue with converting a DateTime stamp received from the backend into a more formatted string in Flutter. I'm aiming to display the date as "June 10th, 2024".

What have you tried so far?

Here's what I've tried:

  1. I attempted to create a custom function to format the DateTime.

  2. I encountered a type error: "String is not a subtype of DateTime".

It seems like there's a mismatch in data types somewhere in my code. Could anyone help me troubleshoot this or provide a snippet that could handle this conversion correctly?


import 'dart:convert';

import 'dart:math' as math;

import 'package:flutter/material.dart';

import 'package:google_fonts/google_fonts.dart';

import 'package:intl/intl.dart';

import 'package:timeago/timeago.dart' as timeago;

import '/flutter_flow/lat_lng.dart';

import '/flutter_flow/place.dart';

import '/flutter_flow/uploaded_file.dart';

import '/flutter_flow/custom_functions.dart';

import '/backend/backend.dart';

import 'package:cloud_firestore/cloud_firestore.dart';

import '/auth/custom_auth/auth_util.dart';

DateTime? convertDate(dynamic date) {

  /// MODIFY CODE ONLY BELOW THIS LINE

  // convert  date timestamp  into yMMMd

  if (date == null) return null;

  final format = DateFormat.yMMMd();

  return format.format(date);

  /// MODIFY CODE ONLY ABOVE THIS LINE

}

Did you check FlutterFlow's Documentation for this topic?
Yes
5
5 replies